Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- def encryption():
- print("***ENCRYPTION***")
- list_words = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n"," ","o","p","q","r","s","t","u","v","w","x","y","z"]
- keyword = input("Keyword = ")
- keyword_list = list(keyword)
- random_numbers_list = []
- i= 1
- while i<= len(keyword):
- random_numbers_list.append(random.randint(1,27))
- i+=1
- variable_numbers_list = []
- j= 0
- while j<= len(keyword)-1 :
- variable_numbers_list.append((list_words.index(keyword_list[j]) + random_numbers_list[j]) % 26)
- j+=1
- k = 0
- plaintext = ""
- while k<= len(keyword)-1:
- plaintext = plaintext + list_words[variable_numbers_list[k]]
- k+=1
- #RESULTS
- l = 0
- key = ""
- while l<= len(keyword)-1 :
- if l<1:
- key = str(random_numbers_list[l])
- else:
- key = key + ", " + str(random_numbers_list[l])
- l+=1
- print("\nPlaintext: '{}'".format(keyword))
- print("Key: '{}'".format(key))
- print("Ciphertext: '{}'".format(plaintext))
- def decryption():
- print("\n***DECRYPTION***")
- list_words = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n"," ","o","p","q","r","s","t","u","v","w","x","y","z"]
- keyword = input("Keyword = ")
- keyword_list = list(keyword)
- key_numbers_list = []
- i = 1
- while i<= len(keyword):
- key_numbers_list.append(int(input("Key Number: ")))
- i+=1
- variable_numbers_list = []
- j = 0
- while j<= len(keyword)-1:
- variable_numbers_list.append((list_words.index(keyword_list[j]) - key_numbers_list[j]) % 26)
- j+=1
- k = 0
- plaintext = ""
- while k<= len(keyword)-1:
- plaintext = plaintext + list_words[variable_numbers_list[k]]
- k+=1
- print("\nCiphertext: '{}'".format(keyword))
- print("Plaintext: '{}'".format(plaintext))
- encryption()
- decryption()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement