# Copyright 2007 The American Cryptogram Association (ACA) # 3613 Piedmont Drive, Plano, TX 75075-6234. # All rights reserved. # POLLUX GENETIC by ANCHISES # On 2.4GHz P4 runs at 610 keys per sec & solves in about 30 seconds #--------------------------------------------------------------------- from random import shuffle,randrange #.....data to decode morse...... letter=['a']*200 # set up array letter[][] for j in range(5): letter[j]=['a']*20 letter[1]="et" letter[2]="ianm" letter[3]="surwdkgo" # 2**3=8 possible values letter[4]="hvf-l-pjbxcyzq--" # 2**4=16 possible values plain=['a']*1000 # set up array plain[1000] symbol = '.-x' #morse symbols represented by 0,1,2 in program #.....load tetragraphs from binary file..... InFile = open("TetraLogFreq.bin","rb") temp_string = InFile.read() InFile.close() a = [None ]*26 # put tetra log freqs into a[26][26][26][26] index = 0 for i1 in range(26): a[i1]=[None]*26 for i2 in range(26): a[i1][i2]=[None]*26 for i3 in range(26): a[i1][i2][i3]=[None]*26 for i4 in range(26): a[i1][i2][i3][i4]=ord(temp_string[2*index])+256*ord(temp_string[2*index+1]) index += 1 #.....paste ciphertext here.... codetext ="\ 64773 41231 42005 85791 53805 69738 95146 30048 82042 94015 97795 92083\ 12361 74921 33373 07569 78992 17683 14875 82215 37596 74376 03257 09685\ 05541 97064 62064 13849 11926 04991 24319 57155 03800 28927 84273 33736\ 14073 43155 32018 21901 90333 17669 50878 51945 03811 58032 02943 76540\ 63614 59477 37552 80870 98421 53769 21783 21449 02458 05965 78195 20755\ 38749 91696 78941 24064 20966 10697 36746 60036 45723 21263 08267 28687\ 51958 01588 21621 94004 14940 74850 21891 41288 800" lenc=len(codetext); #....remove spaces & create array ct[] of ciphertext..... t=-1 ct=[0]*1000 for j in range (lenc): if codetext[j] != ' ': t+=1 ct[t] = int(codetext[j]) # string to integer lenc=t+1 #print "length of ciphertext= ", lenc #print def make_parent(): array=[0]*10 c=range(10) # make random nr 0->9 shuffle(c) for k in range(10): # 0 to 3 gives 0, dit if c[k]<4: array[k]=0 elif c[k]<7: # 4 to 6 gives 1, dah array[k]=1 else: array[k]=2 # 7 to 9 gives 2, x return(array) def make_morse(array): t = -1 for p in range(lenc): t+=1 morse[t]=array[ct[p]] return(morse,t+1) #send back morse[] & length def decipher(morse,lenm): len_plain=0 j=t=-1 while jmaxscore: maxscore=fit[j] print pop,"parents made" #.....make children..... bad=0 while bad<60: #end when 60 consecutive children no better than parents x=randrange(pop) # x is 1st parent y=randrange(pop) # y is 2nd parent z=randrange(10) # z is split position for m in range(z): #make child child[m]=parent[x][m]; for m in range(z,10): child[m]=parent[y][m]; nok+=1 morse,lenm=make_morse(child) plain,len_plain=decipher(morse,lenm); child_score=get_score(plain,len_plain); #...replace parent with child, where child better flag=-1 if fit[x]>fit[y] and child_score>fit[y]: flag=y elif fit[x]fit[x]: flag=x if(flag>-1): for m in range(10): parent[flag][m]=child[m] fit[flag]=child_score bad=0 else: bad+=1 if child_score>maxscore: maxscore=child_score print "Nr of keys=",nok," maxscore=",child_score," key= ", for m in range(10): print symbol[child[m]], print for m in range(len_plain): print plain[m], print print "End Nr of keys =",nok if maxscore<1000: print "Full solution not found...run program again"