SharedEncode dan decode.ipynbOpen in CoCalc
Author: Assamannaha TV
Views : 22
In [16]:
import numpy as np import datetime input = raw_input('Write Text: ') output = [] for character in input: number = ord(character) - 96 output.append(number) a=str(datetime.datetime.now()) a=float(a[20:26]) if a<=9: a=a*111111 elif a>=10 and a<=99: a=a*10101 elif a>=100 and a<=999: a=a*1001 elif a>=1000 and a<=9999: a=a*100 elif a>=10000 and a<= 99999: a=a*10 else: a=a b=int(pow(a,16)-1) c=[int(i) for i in str(b)] c=np.asarray(c) output=np.asarray(output) aa=len(output)//len(c) ab=len(output)%len (c) if len(output) <=len(c)-1: d=output-c[:(len(output))] elif aa>=1 and ab>=1: d=output-(np.append(c[:ab],np.tile(c,aa))) else: d=output-np.tile(c,aa) hasil=[] for code in d: huruf= chr(code + 96) hasil.append(huruf) encode= ''.join(hasil) f = open('encode.txt','w') f.write(encode) f.close() print encode
Write Text:
]`_]
In [ ]:
In [17]:
output
array([0, 1, 2, 3])
In [8]:
b
108684785159301792504261006487586993229760856654790580630453734310670737616623598660453662720L
In [9]:
c
array([1, 0, 8, 6, 8, 4, 7, 8, 5, 1, 5, 9, 3, 0, 1, 7, 9, 2, 5, 0, 4, 2, 6, 1, 0, 0, 6, 4, 8, 7, 5, 8, 6, 9, 9, 3, 2, 2, 9, 7, 6, 0, 8, 5, 6, 6, 5, 4, 7, 9, 0, 5, 8, 0, 6, 3, 0, 4, 5, 3, 7, 3, 4, 3, 1, 0, 6, 7, 0, 7, 3, 7, 6, 1, 6, 6, 2, 3, 5, 9, 8, 6, 6, 0, 4, 5, 3, 6, 6, 2, 7, 2, 0])
In [2]:
import numpy as np import pandas as pd import datetime f = open('encode.txt','r') input = f.read() f.close() output = [] for character in input: number = ord(character) - 96 output.append(number) output=np.asarray(output) aa=len(output)//len(c) ab=len(output)%len(c) if len(output) <=len(c)-1: d=output+c[:(len(output))] elif aa>=1 and ab>=1: d=output+(np.append(c[:ab],np.tile(c,aa))) else: d=output+np.tile(c,aa) hasil=[] for code in d: huruf= chr(code + 96) hasil.append(huruf) decode= ''.join(hasil) f = open('decode.txt','w') f.write(decode) f.close() print decode
saya pernah nembak dita tapi ditolak
In [2]:
import numpy as np import datetime input = raw_input('Write Text: ') output = [] for character in input: number = ord(character) - 96 output.append(number) a1=[i+1 for i,x in enumerate(output) if x == -64] insert=dict() insert_elements = [3, 5, 6] for i in range(len(a1)+1): insert[i]=sum(a1[:i])+i*len(insert_elements) output[insert[i]:insert[i]]=insert_elements a=str(datetime.datetime.now()) a=float(a[20:26]) if a<=9: a=a*111111 elif a>=10 and a<=99: a=a*10101 elif a>=100 and a<=999: a=a*1001 elif a>=1000 and a<=9999: a=a*100 elif a>=10000 and a<= 99999: a=a*10 else: a=a b=int(pow(a,2)-1) c=[int(i) for i in str(b)] c=np.asarray(c) output=np.asarray(output) aa=len(output)//len(c) ab=len(output)%len (c) if len(output) <=len(c)-1: d=output-c[:(len(output))] elif aa>=1 and ab>=1: d=output-(np.append(c[:ab],np.tile(c,aa))) else: d=output-np.tile(c,aa) hasil=[] for code in d: huruf= chr(code + 96) hasil.append(huruf) encode= ''.join(hasil) f = open('encode.txt','w') f.write(encode) f.close() print encode
Write Text:
j^x]ZamoX ac_
In [4]:
output
array([ 19, 1, 25, 1, -64, 3, 9, 14, 20, 1, -64, 4, 9, 1])
In [5]:
[i for i,x in enumerate(output) if x == -64]
[4, 10]
In [93]:
import numpy as np import datetime input = raw_input('Write Text: ') output = [] for character in input: number = ord(character) - 96 output.append(number)
Write Text:
In [94]:
output
[1, 1, -64, 1, 1, -64, 1, 1]
In [95]:
a1=[i+1 for i,x in enumerate(output) if x == -64] a1
[3, 6]
In [96]:
a1=[i+1 for i,x in enumerate(output) if x == -64] insert=dict() insert_elements = [3, 5, 6] for i in range(len(a1)+1): insert[i]=sum(a1[:i])+i*len(insert_elements) output[insert[i]:insert[i]]=insert_elements
In [97]:
output
[3, 5, 6, 1, 1, -64, 3, 5, 6, 1, 1, -64, 1, 1, 3, 5, 6]
In [ ]:
In [82]:
output
[3, 5, 6, 1, 2, -64, 3, 5, 6, 1, 2, -64, 1, 2, 3, 5, 6]
In [ ]:
In [ ]:
In [230]:
import numpy as np import datetime input = raw_input('Write Text: ') output = [] for character in input: number = ord(character) - 96 output.append(number) print output a=str(datetime.datetime.now()) a=float(a[20:26]) if a<=9: a=a*111111 elif a>=10 and a<=99: a=a*10101 elif a>=100 and a<=999: a=a*1001 elif a>=1000 and a<=9999: a=a*100 elif a>=10000 and a<= 99999: a=a*10 else: a=a b=int(pow(a,2)-1) c=[int(i) for i in str(b)] c=np.asarray(c) a1=[i+1 for i,x in enumerate(output) if x == -64] insert=dict() jumlah=[] insert_elements = dict() for i in range(len(a1)+1): jumlah.append(c[i]) insert_elements[i]=c[:jumlah[i]] insert[i]=sum(a1[:i])+sum(jumlah[:i]) output[insert[i]:insert[i]]=insert_elements[i] output=np.asarray(output) aa=len(output)//len(c) ab=len(output)%len (c) if len(output) <=len(c)-1: d=output-c[:(len(output))] elif aa>=1 and ab>=1: d=output-(np.append(c[:ab],np.tile(c,aa))) else: d=output-np.tile(c,aa) hasil=[] for code in d: huruf= chr(code + 96) hasil.append(huruf) encode= ''.join(hasil) f = open('encode.txt','w') f.write(encode) f.close() print encode
Write Text:
[3, 15, 2, 1, -64, 12, 1, 7, 9, -64, 1, 10, 1] ``]lZX^\h`eg^bX^^`_gd
In [231]:
insert_elements
{0: array([2, 2]), 1: array([2, 2]), 2: array([2, 2, 6, 3, 8, 9])}
In [232]:
output
array([ 2, 2, 3, 15, 2, 1, -64, 2, 2, 12, 1, 7, 9, -64, 1, 10, 1, 2, 2, 6, 3, 8, 9])
In [181]:
test=[] for i in range (2): test.append(insert_elements[i])
In [221]:
import numpy as np import datetime input = raw_input('Write Text: ') output = [] for character in input: number = ord(character) - 96 output.append(number) a=str(datetime.datetime.now()) a=float(a[20:26]) if a<=9: a=a*111111 elif a>=10 and a<=99: a=a*10101 elif a>=100 and a<=999: a=a*1001 elif a>=1000 and a<=9999: a=a*100 elif a>=10000 and a<= 99999: a=a*10 else: a=a b=int(pow(a,2)-1) c=[int(i) for i in str(b)] a1=[i+1 for i,x in enumerate(output) if x == -64] insert=dict() jumlah=[] insert_elements = dict() for i in range(len(a1)+1): jumlah.append(c[i]) insert_elements[i]=c[:jumlah[i]] insert[i]=sum(a1[:i])+sum(jumlah[:i]) output[insert[i]:insert[i]]=insert_elements[i]
Write Text:
In [222]:
jumlah
[5, 8, 2]
In [223]:
insert_elements
{0: [5, 8, 2, 1, 0], 1: [5, 8, 2, 1, 0, 3, 3, 8], 2: [5, 8]}
In [224]:
output
[5, 8, 2, 1, 0, 1, 16, 1, -64, 5, 8, 2, 1, 0, 3, 3, 8, 1, 16, 1, -64, 1, 16, 1, 5, 8]
In [215]:
test=[] for i in range (3): test.append(len(insert_elements[i]))
In [220]:
sum(test[:2])
10
In [207]:
test[0,0]
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-207-a0b9efa9e575> in <module>() ----> 1 test[Integer(0),Integer(0)] TypeError: list indices must be integers, not tuple
In [121]:
c
array([8, 5, 9, 6, 4, 4, 2, 0, 8, 8, 9, 9])
In [122]:
jumlah
{0: 8, 1: 5, 2: 9}
In [123]:
insert_elements
{0: array([8, 5, 9, 6, 4, 4, 2, 0]), 1: array([8, 5, 9, 6, 4]), 2: array([8, 5, 9, 6, 4, 4, 2, 0, 8])}
In [124]:
output
array([ 8, 5, 9, 6, 4, 4, 2, 8, 5, 9, 6, 4, 0, 3, 15, 2, 1, -64, 1, 10, 8, 5, 9, 6, 4, 4, 2, 0, 8, 1, -64, 12, 1, 7, 9])
In [ ]:
In [45]:
sum(a1[:2])
14
In [83]:
output
[3, 5, 6, 1, 2, -64, 3, 5, 6, 1, 2, -64, 1, 2, 3, 5, 6]
In [84]:
output[1]
5
In [14]:
mas[1]
5
In [12]:
range(1,4)
[1, 2, 3]
In [45]:
insert=dict() insert_elements = [3, 5, 6] for i in a1: insert[i]=i+insert[i-1] output[ini:i] = insert_elements
In [46]:
output
[1, 4, 1, -64, 1, -64, 3, 5, 6, 2, 3, 5, 6]
In [ ]:
a = [1, 2, 4] insert_at = 2 # List of elements that you want to insert together at "index_at" (above) position >>> insert_elements = [3, 5, 6] >>> a[insert_at:insert_at] = insert_elements >>> a # [3, 5, 6] are inserted together in `a` starting at index "2" [1, 2, 3, 5, 6, 4]
In [20]:
output[3]+a
[19, 1, 19, 1]
In [5]:
# A utility function that decide which two parents two select for crossover. # based on Roulette Wheel Sampling def select_parent(): # totalFitness is sum of fitness of all the organism of the current generation pick = random.randint(0, totalFitness) current = 0 # Roulette Wheel Sampling implementation # populationSize = 10 * length(targetString) for index in range(populationSize): current += fitness_all[index] if current >= pick: return index # A utility function to perform crossover. def produce_next_generation(): for organism in nextGeneration: # select two parents using Roulette Wheel Sampling parent_first = currentGeneration[select_parent()] parent_second = currentGeneration[select_parent()] cross_over_point = random.randint(0, targetLength - 1) new_genes = [''] * targetLength for i in range(targetLength): # mutation rate is set to 0.001 mutate_this_gene = random.randint(0, int(1 / mutationRate)) # target string contains upper and lower case chars only if mutate_this_gene == 0: new_genes[i] = random.choice(string.ascii_uppercase + string.ascii_lowercase) # target string is combination of upper and lower case elif i <= cross_over_point: new_genes[i] = parent_first.genes[i] else: new_genes[i] = parent_second.genes[i] organism.genes = ''.join(new_genes) global currentGeneration currentGeneration = [organism for organism in nextGeneration]
<ipython-input-5-d33c22117204>:38: SyntaxWarning: name 'currentGeneration' is used prior to global declaration global currentGeneration
In [6]:
import numpy import GA """ The y=target is to maximize this equation ASAP: y = w1x1+w2x2+w3x3+w4x4+w5x5+6wx6 where (x1,x2,x3,x4,x5,x6)=(4,-2,3.5,5,-11,-4.7) What are the best values for the 6 weights w1 to w6? We are going to use the genetic algorithm for the best possible values after a number of generations. """ # Inputs of the equation. equation_inputs = [4,-2,3.5,5,-11,-4.7] # Number of the weights we are looking to optimize. num_weights = 6 """ Genetic algorithm parameters: Mating pool size Population size """ sol_per_pop = 8 num_parents_mating = 4 # Defining the population size. pop_size = (sol_per_pop,num_weights) # The population will have sol_per_pop chromosome where each chromosome has num_weights genes. #Creating the initial population. new_population = numpy.random.uniform(low=-4.0, high=4.0, size=pop_size) print(new_population) num_generations = 5 for generation in range(num_generations): print("Generation : ", generation) # Measing the fitness of each chromosome in the population. fitness = GA.cal_pop_fitness(equation_inputs, new_population) # Selecting the best parents in the population for mating. parents = GA.select_mating_pool(new_population, fitness, num_parents_mating) # Generating next generation using crossover. offspring_crossover = GA.crossover(parents, offspring_size=(pop_size[0]-parents.shape[0], num_weights)) # Adding some variations to the offsrping using mutation. offspring_mutation = GA.mutation(offspring_crossover) # Creating the new population based on the parents and offspring. new_population[0:parents.shape[0], :] = parents new_population[parents.shape[0]:, :] = offspring_mutation # The best result in the current iteration. print("Best result : ", numpy.max(numpy.sum(new_population*equation_inputs, axis=1))) # Getting the best solution after iterating finishing all generations. #At first, the fitness is calculated for each solution in the final generation. fitness = GA.cal_pop_fitness(equation_inputs, new_population) # Then return the index of that solution corresponding to the best fitness. best_match_idx = numpy.where(fitness == numpy.max(fitness)) print("Best solution : ", new_population[best_match_idx, :]) print("Best solution fitness : ", fitness[best_match_idx])
--------------------------------------------------------------------------- ImportError Traceback (most recent call last) <ipython-input-6-546e4f1516a4> in <module>() 1 import numpy ----> 2 import GA 3 4 """ 5 The y=target is to maximize this equation ASAP: ImportError: No module named GA
In [1]:
import random # # Global variables # Setup optimal string and GA input variables. # OPTIMAL = "satu" DNA_SIZE = len(OPTIMAL) POP_SIZE = 20 GENERATIONS = 5000 # # Helper functions # These are used as support, but aren't direct GA-specific functions. # def weighted_choice(items): weight_total = sum((item[1] for item in items)) n= random.uniform(0, weight_total) for item, weight in items: if n < weight: return item n = n - weight return item def random_char(): """ Return a random character between ASCII 32 and 126 (i.e. spaces, symbols, letters, and digits). All characters returned will be nicely printable. """ return chr(int(random.randrange(32, 126, 1))) def random_population(): pop = [] for i in xrange(POP_SIZE): dna = "" for c in xrange(DNA_SIZE): dna += random_char() pop.append(dna) return pop # # GA functions # These make up the bulk of the actual GA algorithm. # def fitness(dna): """ For each gene in the DNA, this function calculates the difference between it and the character in the same position in the OPTIMAL string. These values are summed and then returned. """ fitness = 0 for c in xrange(DNA_SIZE): fitness += abs(ord(dna[c]) - ord(OPTIMAL[c])) return fitness def mutate(dna): """ For each gene in the DNA, there is a 1/mutation_chance chance that it will be switched out with a random character. This ensures diversity in the population, and ensures that is difficult to get stuck in local minima. """ dna_out = "" mutation_chance = 100 for c in xrange(DNA_SIZE): if int(random.random()*mutation_chance) == 1: dna_out += random_char() else: dna_out += dna[c] return dna_out def crossover(dna1, dna2): """ Slices both dna1 and dna2 into two parts at a random index within their length and merges them. Both keep their initial sublist up to the crossover index, but their ends are swapped. """ pos = int(random.random()*DNA_SIZE) return (dna1[:pos]+dna2[pos:], dna2[:pos]+dna1[pos:]) # # Main driver # Generate a population and simulate GENERATIONS generations. # if __name__ == "__main__": # Generate initial population. This will create a list of POP_SIZE strings, # each initialized to a sequence of random characters. population = random_population() # Simulate all of the generations. for generation in xrange(GENERATIONS): print "Generation %s... Random sample: '%s'" % (generation, population[0]) weighted_population = [] # Add individuals and their respective fitness levels to the weighted # population list. This will be used to pull out individuals via certain # probabilities during the selection phase. Then, reset the population list # so we can repopulate it after selection. for individual in population: fitness_val = fitness(individual) # Generate the (individual,fitness) pair, taking in account whether or # not we will accidently divide by zero. if fitness_val == 0: pair = (individual, 1.0) else: pair = (individual, 1.0/fitness_val) weighted_population.append(pair) population = [] # Select two random individuals, based on their fitness probabilites, cross # their genes over at a random point, mutate them, and add them back to the # population for the next iteration. for _ in xrange(POP_SIZE/2): # Selection ind1 = weighted_choice(weighted_population) ind2 = weighted_choice(weighted_population) # Crossover ind1, ind2 = crossover(ind1, ind2) # Mutate and add back into the population. population.append(mutate(ind1)) population.append(mutate(ind2)) # Display the highest-ranked string after all generations have been iterated # over. This will be the closest string to the OPTIMAL string, meaning it # will have the smallest fitness value. Finally, exit the program. fittest_string = population[0] minimum_fitness = fitness(population[0]) for individual in population: ind_fitness = fitness(individual) if ind_fitness <= minimum_fitness: fittest_string = individual minimum_fitness = ind_fitness print "Fittest String: %s" % fittest_string exit(0)
Generation 0... Random sample: '|?7k' Generation 1... Random sample: '|?7k' Generation 2... Random sample: '|?7k' Generation 3... Random sample: '|?7k' Generation 4... Random sample: '|?7k' Generation 5... Random sample: '|?7k' Generation 6... Random sample: '|?Zk' Generation 7... Random sample: '|?7k' Generation 8... Random sample: '|?7k' Generation 9... Random sample: '|?Zk' Generation 10... Random sample: '|?Zk' Generation 11... Random sample: '|?7k' Generation 12... Random sample: '|?7#' Generation 13... Random sample: '|?7d' Generation 14... Random sample: '|?7k' Generation 15... Random sample: '|?7k' Generation 16... Random sample: '|?Zk' Generation 17... Random sample: '|?7k' Generation 18... Random sample: '|?7k' Generation 19... Random sample: '|?_k' Generation 20... Random sample: '|?_k' Generation 21... Random sample: '|?_k' Generation 22... Random sample: 'F?Zk' Generation 23... Random sample: '|?Zk' Generation 24... Random sample: '|?Zk' Generation 25... Random sample: '|?Zk' Generation 26... Random sample: '|?Zk' Generation 27... Random sample: '|?Zk' Generation 28... Random sample: '|?_S' Generation 29... Random sample: '|?Zk' Generation 30... Random sample: '|?Zk' Generation 31... Random sample: '|?Zk' Generation 32... Random sample: '|?Zk' Generation 33... Random sample: '|?Zk' Generation 34... Random sample: '|?Zk' Generation 35... Random sample: '|?Zk' Generation 36... Random sample: '|?Zk' Generation 37... Random sample: 'v?Zk' Generation 38... Random sample: '|?Zk' Generation 39... Random sample: '|KZk' Generation 40... Random sample: '|KZk' Generation 41... Random sample: '|KZk' Generation 42... Random sample: '|KZk' Generation 43... Random sample: '|?Zk' Generation 44... Random sample: '|KZk' Generation 45... Random sample: '|KZk' Generation 46... Random sample: '|KZk' Generation 47... Random sample: '|KZk' Generation 48... Random sample: '|KZk' Generation 49... Random sample: '|KZk' Generation 50... Random sample: '|KZk' Generation 51... Random sample: '|KZk' Generation 52... Random sample: '|VZk' Generation 53... Random sample: '|Ktk' Generation 54... Random sample: '&KZk' Generation 55... Random sample: '|KZk' Generation 56... Random sample: '|VZk' Generation 57... Random sample: '|Ktk' Generation 58... Random sample: '|VZk' Generation 59... Random sample: '|Ktk' Generation 60... Random sample: '|Vtk' Generation 61... Random sample: '|Ktk' Generation 62... Random sample: '|Vtk' Generation 63... Random sample: '|Vtk' Generation 64... Random sample: '|Vtk' Generation 65... Random sample: '|Vtk' Generation 66... Random sample: '|Vtk' Generation 67... Random sample: '|VtZ' Generation 68... Random sample: '|Vtk' Generation 69... Random sample: '|Vtk' Generation 70... Random sample: '|Vtk' Generation 71... Random sample: '|Vyk' Generation 72... Random sample: '|Vtk' Generation 73... Random sample: '|Vyk' Generation 74... Random sample: '|Vtk' Generation 75... Random sample: '|Vtk' Generation 76... Random sample: '|Vy ' Generation 77... Random sample: '|Vtk' Generation 78... Random sample: '|Vtk' Generation 79... Random sample: '|Vtk' Generation 80... Random sample: '|Vtk' Generation 81... Random sample: '|Vtk' Generation 82... Random sample: '|Vtk' Generation 83... Random sample: '|Vtk' Generation 84... Random sample: '|Vtk' Generation 85... Random sample: '|Vtk' Generation 86... Random sample: '|Vtk' Generation 87... Random sample: '|Vtk' Generation 88... Random sample: '|Vtk' Generation 89... Random sample: '|Vtk' Generation 90... Random sample: '|Vtk' Generation 91... Random sample: '|Vtk' Generation 92... Random sample: '|Vtk' Generation 93... Random sample: '|Vtk' Generation 94... Random sample: '|Vtk' Generation 95... Random sample: '|utk' Generation 96... Random sample: '|Vtk' Generation 97... Random sample: '|Vtk' Generation 98... Random sample: '|Vtk' Generation 99... Random sample: '|Vtk' Generation 100... Random sample: '|Vtk' Generation 101... Random sample: '|Vtk' Generation 102... Random sample: '|Vtk' Generation 103... Random sample: '|Vtk' Generation 104... Random sample: '|ftk' Generation 105... Random sample: '|Vtk' Generation 106... Random sample: '|ntk' Generation 107... Random sample: '|ftk' Generation 108... Random sample: '|Vtk' Generation 109... Random sample: '|ftk' Generation 110... Random sample: '|Vtk' Generation 111... Random sample: '|ftk' Generation 112... Random sample: '|ftk' Generation 113... Random sample: '|ftk' Generation 114... Random sample: '|ftk' Generation 115... Random sample: '|ftk' Generation 116... Random sample: '|ftk' Generation 117... Random sample: '|ftk' Generation 118... Random sample: '|ftk' Generation 119... Random sample: '|ftq' Generation 120... Random sample: '|ftq' Generation 121... Random sample: '|ftk' Generation 122... Random sample: '|ftq' Generation 123... Random sample: '|ftq' Generation 124... Random sample: '|ftk' Generation 125... Random sample: '|ftq' Generation 126... Random sample: '|ftq' Generation 127... Random sample: '|ftk' Generation 128... Random sample: '|ftk' Generation 129... Random sample: '|ftq' Generation 130... Random sample: '|ftq' Generation 131... Random sample: 'qftq' Generation 132... Random sample: 'qftq' Generation 133... Random sample: 'qftq' Generation 134... Random sample: 'qftq' Generation 135... Random sample: 'qfWq' Generation 136... Random sample: 'qftq' Generation 137... Random sample: 'qftq' Generation 138... Random sample: 'qftq' Generation 139... Random sample: 'qftq' Generation 140... Random sample: 'qftq' Generation 141... Random sample: 'qftq' Generation 142... Random sample: 'qftq' Generation 143... Random sample: 'qftq' Generation 144... Random sample: 'qftq' Generation 145... Random sample: 'qftq' Generation 146... Random sample: 'xftq' Generation 147... Random sample: 'qftq' Generation 148... Random sample: 'qftq' Generation 149... Random sample: 'qftq' Generation 150... Random sample: 'qftq' Generation 151... Random sample: 'qitq' Generation 152... Random sample: 'qgtq' Generation 153... Random sample: 'qgtq' Generation 154... Random sample: 'qgtq' Generation 155... Random sample: 'qftq' Generation 156... Random sample: 'qitq' Generation 157... Random sample: 'qftq' Generation 158... Random sample: 'qftq' Generation 159... Random sample: 'q6tq' Generation 160... Random sample: 'qftq' Generation 161... Random sample: 'qftq' Generation 162... Random sample: 'qftq' Generation 163... Random sample: 'qftq' Generation 164... Random sample: 'qftq' Generation 165... Random sample: 'qftq' Generation 166... Random sample: 'qftq' Generation 167... Random sample: 'qftq' Generation 168... Random sample: 'qftq' Generation 169... Random sample: 'qftq' Generation 170... Random sample: 'qftq' Generation 171... Random sample: 'qftq' Generation 172... Random sample: 'qftq' Generation 173... Random sample: 'qftq' Generation 174... Random sample: 'qftq' Generation 175... Random sample: 'qftq' Generation 176... Random sample: 'qftq' Generation 177... Random sample: 'qftq' Generation 178... Random sample: 'qftq' Generation 179... Random sample: 'qftq' Generation 180... Random sample: 'qftq' Generation 181... Random sample: 'qftq' Generation 182... Random sample: 'qfts' Generation 183... Random sample: 'qftq' Generation 184... Random sample: 'qfts' Generation 185... Random sample: 'qftq' Generation 186... Random sample: 'qftq' Generation 187... Random sample: 'qftq' Generation 188... Random sample: 'qfts' Generation 189... Random sample: 'qfts' Generation 190... Random sample: 'qfts' Generation 191... Random sample: 'qfts' Generation 192... Random sample: 'qftl' Generation 193... Random sample: 'qfts' Generation 194... Random sample: 'qfts' Generation 195... Random sample: 'qfts' Generation 196... Random sample: 'qfts' Generation 197... Random sample: 'qfts' Generation 198... Random sample: 'qfts' Generation 199... Random sample: 'qfts' Generation 200... Random sample: 'qfts' Generation 201... Random sample: 'qfts' Generation 202... Random sample: 'qfts' Generation 203... Random sample: 'qfts' Generation 204... Random sample: 'qfts' Generation 205... Random sample: 'qfts' Generation 206... Random sample: 'qfts' Generation 207... Random sample: 'q^ts' Generation 208... Random sample: 'qfts' Generation 209... Random sample: 'qfts' Generation 210... Random sample: 'q^ts' Generation 211... Random sample: 'q^ts' Generation 212... Random sample: 'q^ks' Generation 213... Random sample: 'qfts' Generation 214... Random sample: 'qfts' Generation 215... Random sample: 'qfts' Generation 216... Random sample: 'q^ts' Generation 217... Random sample: 'q^ts' Generation 218... Random sample: 'q^ts' Generation 219... Random sample: 'q^ts' Generation 220... Random sample: 'q^ts' Generation 221... Random sample: 'q^ts' Generation 222... Random sample: 'q^ts' Generation 223... Random sample: 'q^ts' Generation 224... Random sample: 'q^ts' Generation 225... Random sample: 'q^ts' Generation 226... Random sample: 'q^ts' Generation 227... Random sample: 'q^ts' Generation 228... Random sample: 'q^ts' Generation 229... Random sample: 'q^ts' Generation 230... Random sample: 'q^ts' Generation 231... Random sample: 'q^ts' Generation 232... Random sample: 'q^ts' Generation 233... Random sample: 'q^ts' Generation 234... Random sample: 'q^ts' Generation 235... Random sample: 'q^ts' Generation 236... Random sample: 'q^ts' Generation 237... Random sample: 'q^ts' Generation 238... Random sample: 'q^ts' Generation 239... Random sample: 'q^ts' Generation 240... Random sample: 'q^ts' Generation 241... Random sample: 'q^ts' Generation 242... Random sample: 'q^ts' Generation 243... Random sample: 'q^ts' Generation 244... Random sample: 'q^ts' Generation 245... Random sample: 'q^ts' Generation 246... Random sample: 'q^ts' Generation 247... Random sample: 'q^ts' Generation 248... Random sample: 'q^ts' Generation 249... Random sample: 'q^ts' Generation 250... Random sample: 'q^ts' Generation 251... Random sample: 'q^ts' Generation 252... Random sample: 'q^ts' Generation 253... Random sample: 'M^ts' Generation 254... Random sample: 'q^ts' Generation 255... Random sample: 'q^ts' Generation 256... Random sample: 'q^ts' Generation 257... Random sample: 'q^ts' Generation 258... Random sample: 'qOts' Generation 259... Random sample: 'q^ts' Generation 260... Random sample: 'q^ts' Generation 261... Random sample: 'q^ts' Generation 262... Random sample: 'q^ts' Generation 263... Random sample: 'q^ts' Generation 264... Random sample: 'q^ts' Generation 265... Random sample: 'q^ts' Generation 266... Random sample: 'q^ts' Generation 267... Random sample: 'q^ts' Generation 268... Random sample: 'q^ts' Generation 269... Random sample: 'q^ts' Generation 270... Random sample: 'q^ts' Generation 271... Random sample: 'q^ts' Generation 272... Random sample: 'q^ts' Generation 273... Random sample: 'q^ts' Generation 274... Random sample: 'q^ts' Generation 275... Random sample: 'q^ts' Generation 276... Random sample: 'q^ts' Generation 277... Random sample: 'q^ts' Generation 278... Random sample: 'q^ts' Generation 279... Random sample: 'q^ts' Generation 280... Random sample: 'q^ts' Generation 281... Random sample: 'q^ts' Generation 282... Random sample: 'q^ts' Generation 283... Random sample: 'q^ts' Generation 284... Random sample: 'q^ts' Generation 285... Random sample: 'q^ts' Generation 286... Random sample: 'q^ts' Generation 287... Random sample: 'q^ts' Generation 288... Random sample: 'q^ts' Generation 289... Random sample: 'q^ts' Generation 290... Random sample: 'q^ts' Generation 291... Random sample: 'q^ts' Generation 292... Random sample: 'q^ts' Generation 293... Random sample: 'q^:s' Generation 294... Random sample: 'q^ts' Generation 295... Random sample: 'q^ts' Generation 296... Random sample: 'q^ts' Generation 297... Random sample: 'u^ts' Generation 298... Random sample: 'q^ts' Generation 299... Random sample: 'u^ts' Generation 300... Random sample: 'q^us' Generation 301... Random sample: 'u^us' Generation 302... Random sample: 'q^ts' Generation 303... Random sample: 'u^ts' Generation 304... Random sample: 'q^ts' Generation 305... Random sample: 'u^ts' Generation 306... Random sample: 'u^ts' Generation 307... Random sample: 'q^ts' Generation 308... Random sample: 'u^ts' Generation 309... Random sample: 'q^ts' Generation 310... Random sample: 'q^ts' Generation 311... Random sample: 'u^ts' Generation 312... Random sample: 'q^ts' Generation 313... Random sample: 'u^ts' Generation 314... Random sample: 'q^ts' Generation 315... Random sample: 'q^ts' Generation 316... Random sample: 'q^ts' Generation 317... Random sample: 'q^ts' Generation 318... Random sample: 'q^ts' Generation 319... Random sample: 'q^ts' Generation 320... Random sample: 'q^ts' Generation 321... Random sample: 'q^ts' Generation 322... Random sample: 'q^ts' Generation 323... Random sample: 'q^ts' Generation 324... Random sample: 'q^ts' Generation 325... Random sample: 'q^ts' Generation 326... Random sample: 'q^ts' Generation 327... Random sample: 'q^ts' Generation 328... Random sample: 'q^ts' Generation 329... Random sample: 'q^ts' Generation 330... Random sample: 'q^ts' Generation 331... Random sample: 'q^ts' Generation 332... Random sample: 'q^ts' Generation 333... Random sample: 'q^ts' Generation 334... Random sample: 'q^ts' Generation 335... Random sample: 'q^ts' Generation 336... Random sample: 'q^ts' Generation 337... Random sample: 'q^ts' Generation 338... Random sample: 'q^ts' Generation 339... Random sample: 'q^ts' Generation 340... Random sample: 'q^ts' Generation 341... Random sample: 'q^ts' Generation 342... Random sample: 'q^ts' Generation 343... Random sample: 'q^ts' Generation 344... Random sample: 'q^ts' Generation 345... Random sample: 'q^ts' Generation 346... Random sample: 'q^ts' Generation 347... Random sample: 'q^ts' Generation 348... Random sample: 'q^ts' Generation 349... Random sample: 'qrts' Generation 350... Random sample: 'q^ts' Generation 351... Random sample: 'q^ts' Generation 352... Random sample: 'q^ts' Generation 353... Random sample: 'q^ts' Generation 354... Random sample: 'q^ts' Generation 355... Random sample: 'q^ts' Generation 356... Random sample: 'q^ts' Generation 357... Random sample: 'q^ks' Generation 358... Random sample: 'q^ts' Generation 359... Random sample: 'q^ts' Generation 360... Random sample: 'q^ts' Generation 361... Random sample: 'q^ts' Generation 362... Random sample: '?^ts' Generation 363... Random sample: 'q^ts' Generation 364... Random sample: 'q^ts' Generation 365... Random sample: 'q^ts' Generation 366... Random sample: 'q^ts' Generation 367... Random sample: 'q^ts' Generation 368... Random sample: 'q^ts' Generation 369... Random sample: 'q^ts' Generation 370... Random sample: 'q^ts' Generation 371... Random sample: 'q^ts' Generation 372... Random sample: 'q^ts' Generation 373... Random sample: 'q^ts' Generation 374... Random sample: 'q^ts' Generation 375... Random sample: 'q^ts' Generation 376... Random sample: 'q^ts' Generation 377... Random sample: 'q^ts' Generation 378... Random sample: 'q^ts' Generation 379... Random sample: 'q^ts' Generation 380... Random sample: 'q^ts' Generation 381... Random sample: 'qTts' Generation 382... Random sample: 'q^ts' Generation 383... Random sample: 'q^ts' Generation 384... Random sample: 'q^ts' Generation 385... Random sample: 'q^ts' Generation 386... Random sample: 'q^ts' Generation 387... Random sample: 'qfts' Generation 388... Random sample: 'q^ts' Generation 389... Random sample: 'q^ts' Generation 390... Random sample: 'q^ts' Generation 391... Random sample: 'q^ts' Generation 392... Random sample: 'q^ts' Generation 393... Random sample: 'q^ts' Generation 394... Random sample: 'q^ts' Generation 395... Random sample: 'q^ts' Generation 396... Random sample: 'q^ts' Generation 397... Random sample: 'q^ts' Generation 398... Random sample: 'q^ts' Generation 399... Random sample: 'q^ts' Generation 400... Random sample: 'q^ts' Generation 401... Random sample: 'q^ts' Generation 402... Random sample: 'q^ts' Generation 403... Random sample: 'q^ts' Generation 404... Random sample: 'c^ts' Generation 405... Random sample: 'q^ts' Generation 406... Random sample: 'q^ts' Generation 407... Random sample: 'q^ts' Generation 408... Random sample: 'q^ts' Generation 409... Random sample: 'q^ts' Generation 410... Random sample: 't^ts' Generation 411... Random sample: 'q^ts' Generation 412... Random sample: 'q^ts' Generation 413... Random sample: 'q^ts' Generation 414... Random sample: 'q^ts' Generation 415... Random sample: 'q^ts' Generation 416... Random sample: 'q^ts' Generation 417... Random sample: 't^ts' Generation 418... Random sample: 't^tu' Generation 419... Random sample: 't^tu' Generation 420... Random sample: 't^tu' Generation 421... Random sample: 't^tu' Generation 422... Random sample: 't^ts' Generation 423... Random sample: 't^tu' Generation 424... Random sample: 't^ts' Generation 425... Random sample: 't^ts' Generation 426... Random sample: 't^tu' Generation 427... Random sample: 't^t)' Generation 428... Random sample: 't^tu' Generation 429... Random sample: 't^tu' Generation 430... Random sample: 't^tu' Generation 431... Random sample: 't^tu' Generation 432... Random sample: 't^tu' Generation 433... Random sample: 't^tu' Generation 434... Random sample: 't^tu' Generation 435... Random sample: 't^tu' Generation 436... Random sample: 't^tu' Generation 437... Random sample: 't^tu' Generation 438... Random sample: 't^tu' Generation 439... Random sample: 't^tu' Generation 440... Random sample: 't^tu' Generation 441... Random sample: 't^tu' Generation 442... Random sample: 't^tu' Generation 443... Random sample: 't^tu' Generation 444... Random sample: 't^tu' Generation 445... Random sample: 't^tu' Generation 446... Random sample: 't^tu' Generation 447... Random sample: 't^tu' Generation 448... Random sample: 't^tu' Generation 449... Random sample: 't^tu' Generation 450... Random sample: 't^tu' Generation 451... Random sample: 't^tu' Generation 452... Random sample: 't^tu' Generation 453... Random sample: 't^tu' Generation 454... Random sample: 't^tu' Generation 455... Random sample: 't^tu' Generation 456... Random sample: 't^tu' Generation 457... Random sample: 'O^tu' Generation 458... Random sample: 't^tu' Generation 459... Random sample: 't^tu' Generation 460... Random sample: 't^tu' Generation 461... Random sample: 't^tu' Generation 462... Random sample: 't^tu' Generation 463... Random sample: 't^tu' Generation 464... Random sample: 't^tu' Generation 465... Random sample: 't^tu' Generation 466... Random sample: 't^tu' Generation 467... Random sample: 't^tu' Generation 468... Random sample: 't^tu' Generation 469... Random sample: 't^tu' Generation 470... Random sample: 't^tu' Generation 471... Random sample: 't^tu' Generation 472... Random sample: 't^tu' Generation 473... Random sample: 't^tu' Generation 474... Random sample: 't^tu' Generation 475... Random sample: 't^tu' Generation 476... Random sample: 't^tu' Generation 477... Random sample: 't^tu' Generation 478... Random sample: 't^tu' Generation 479... Random sample: 't^tu' Generation 480... Random sample: 't^tu' Generation 481... Random sample: 't^tu' Generation 482... Random sample: 't^tu' Generation 483... Random sample: 't^tu' Generation 484... Random sample: 't^tu'
WARNING: Some output was deleted.
In [1]:
import pyaes # A 256 bit (32 byte) key key = "This_key_for_demo_purposes_only!" plaintext = "Text may be any length you wish, no padding is required" # key must be bytes, so we convert it key = key.encode('utf-8') aes = pyaes.AESModeOfOperationCTR(key) ciphertext = aes.encrypt(plaintext) # show the encrypted data print (ciphertext) # DECRYPTION # CRT mode decryption requires a new instance be created aes = pyaes.AESModeOfOperationCTR(key) # decrypted data is always binary, need to decode to plaintext decrypted = aes.decrypt(ciphertext).decode('utf-8') # True print (decrypted == plaintext)
--------------------------------------------------------------------------- ImportError Traceback (most recent call last) <ipython-input-1-b234f742200b> in <module>() ----> 1 import pyaes 2 3 # A 256 bit (32 byte) key 4 key = "This_key_for_demo_purposes_only!" 5 plaintext = "Text may be any length you wish, no padding is required" ImportError: No module named pyaes
In [ ]: