Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def encode(n, seq):
- its = [iter(seq)]*n
- return zip(*its)
- def Playfair(s):
- keystring = []
- for j in s+ "ABCDEFGHIJKLMNOPQRSTUVWXYZ":
- if j not in keystring:
- keystring.append(j)
- return list(take(5, keystring))
- print (Playfair("EVENTHOUGHTHECOLDWARHASCOMEANDGONEITSCHILLWINDSSTILLBLOW"))
- #[('E', 'V', 'N', 'T', 'H'), ('O', 'U', 'G', 'C', 'L'), ('D', 'W', 'A', 'R', 'S'), ('M', 'I', 'B', 'F', 'J'), ('K', 'P', 'Q', 'X', 'Y')]
- def encode(n, seq):
- its = [iter(seq)]*n
- return zip(*its)
- def Playfair(s):
- keystring = []
- for j in s+ "ABCDEFGHIJKLMNOPQRSTUVWXYZ":
- if j not in keystring:
- keystring.append(j)
- return list(take(5, keystring))
- print (Playfair("All those who believe in psychokinesis raise my hand"))
- #[('A', 'l', ' ', 't', 'h'), ('o', 's', 'e', 'w', 'b'), ('i', 'v', 'n', 'p', 'y'), ('c', 'k', 'r', 'a', 'm'), ('d', 'B', 'C', 'D', 'E'), ('F', 'G', 'H', 'I', 'J'), ('K', 'L', 'M', 'N', 'O'), ('P', 'Q', 'R', 'S', 'T'), ('U', 'V', 'W', 'X', 'Y')]
- alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
- len(alphabet)
- #26
- import random
- alpha2 = []
- for i in alphabet: alpha2.append(i)
- playFair = []
- row = []
- while(len(alpha2))>1:
- index = random.randint(0,len(alpha2)-1)
- row.append(alpha2[index])
- alpha2.remove(alpha2[index])
- if len(row) == 5:
- playFair.append(row)
- row = []
- for row in playFair:
- print(row)
- print("left out letter: ", alpha2)
- #['G', 'R', 'X', 'M', 'F']
- #['J', 'H', 'S', 'V', 'O']
- #['U', 'W', 'L', 'D', 'Z']
- #['I', 'C', 'P', 'A', 'B']
- #['N', 'T', 'E', 'Q', 'Y']
- #left out letter: ['K']
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement