Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- alphabet = []
- for i in range (0,26):
- alphabet.append(chr(ord('A')+i))
- for i in range (0,26):
- alphabet.append(chr(ord('a')+i))
- for i in range (0,10):
- alphabet.append(chr(ord('0')+i))
- alphabet.append(' ')
- alphabet.append('!')
- noCar = '?'
- def modulo(num,mod):
- if num > 0:
- while num > mod-1:
- num -= mod
- return num
- else:
- while num < 0:
- num += mod
- return num
- def AsciiToAlphabet(letter):
- for i in range (0,len(alphabet)):
- if(alphabet[i] == letter):
- return i
- return -1
- def AlphabetToAscii(num):
- if(num >= len(alphabet)):
- return noCar
- else:
- return alphabet[num]
- def Crypt(phrase,passphrase):
- rep = ""
- for i in range (0,len(phrase)):
- rep += AlphabetToAscii(modulo(AsciiToAlphabet(phrase[i]) + AsciiToAlphabet(passphrase[modulo(i,len(passphrase))]),len(alphabet)))
- return rep
- def Uncrypt(phrase,passphrase):
- rep = ""
- for i in range (0,len(phrase)):
- rep += AlphabetToAscii(modulo(AsciiToAlphabet(phrase[i]) - AsciiToAlphabet(passphrase[modulo(i,len(passphrase))]),len(alphabet)))
- return rep
- isContinue = True
- while isContinue:
- mode = input("Quel mode (d/c/q) : ")
- while mode != "d" and mode != "c" and mode != "q":
- mode = input("Entrer (d/c/q)!\nQuel mode (d/c/q) : ")
- if mode == "q":
- isContinue = False
- continue
- word = input("Entrer mot : ")
- passphrase = input("Entrer passphrase : ")
- if mode == "c":
- print(Crypt(word,passphrase))
- else:
- print(Uncrypt(word,passphrase))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement