# cipher tool python(1-3)

Wed Dec 21 2022 10:56:38 GMT+0000 (UTC)

Saved by @ronin_78 #python

def encrypt(message, key):
cipher = ""

for i in range(len(message)):
char = message[i]
keychar = key[i]

if (char.isupper()):
cipher += chr((ord(char) + ord(keychar) - 130) % 26 + 65)

else:
cipher += chr((ord(char) + ord(keychar) - 194) % 26 + 97)

return cipher

def decrypt(cipher, key):
message = ""

for i in range(len(cipher)):
char = cipher[i]
keychar = key[i]

if (char.isupper()):
message += chr((ord(char) - ord(keychar) - 130) % 26 + 65)

else:
message += chr((ord(char) - ord(keychar)) % 26 + 97)

return message

def newkey(text, key):
newkey = ""
length = 1

while length <= len(text):
for i in range(len(key)):
if length <= len(text):
newkey += key[i]
length += 1
else:
break;
return newkey

x = 1
while(x==1):
print("1.Caesar Cipher \n 2.Vernam Cipher \n 3.Vigenere Cipher \n 4.Transposition Cipher \n 5.RSA \n")
Choice = int(input("Choose one of the options above: "))

if Choice == 1:
print("\n1.Encrypt a message \n 2.Decrypt a message\n")
option = int(input("Choose one option from above: "))

if option == 1:
cipher = ""
message = input("Enter your message: ")
shift = int(input("Enter the shift value: "))

for i in range(len(message)):
char = message[i]

if (char.isupper()):
cipher += chr((ord(char) + shift - 65) % 26 + 65)

else:
cipher += chr((ord(char) + shift - 97) % 26 + 97)

if option == 2:
message = ""
cipher = input("Enter your Cipher text: ")
shift = int(input("Enter the shift value: "))

for i in range(len(cipher)):
char = cipher[i]

if (char.isupper()):
message += chr((ord(char) - shift - 65) % 26 + 65)

else:
message += chr((ord(char) - shift - 97) % 26 + 97)

elif Choice == 2:
print("1.Encrypt a message")
print("2.Decrypt a cipher")
option = int(input("Choose one option from above: "))

if option == 1:
message = input("Enter your message : ")
key = input("Enter the key: ")

print("Your cipher text = ",encrypt(message, key))

elif option == 2:
cipher = input("Enter the cipher text: ")
key = input("Enter the key: ")

print("Your decrypted message = ",decrypt(cipher, key))

elif Choice == 3:
print("1.Encrypt a message")
print("2.Decrypt a cipher")
option = int(input("Choose one option from above: "))

if option == 1:
message = input("Enter your message: ")
key = input("Enter the key: ")

key = newkey(message, key)

elif option == 2:
message = ""
cipher = input("Enter the cipher text: ")
key = input("Enter the key: ")

key = newkey(cipher, key)