24
loading...
This website collects cookies to deliver better user experience
Nabroleonx
4
Refvspisr|
ord()
function to convert a character to its integer position in the ASCII table( i.e. ord(A)
will give 65).chr()
to return the character from the ASCII table that represents the specified Unicode( i.e. chr(65)
will give "A").ord()
to change our characters to their integer equivalent in the ASCII table.position = ord(char) - ord(" ")
position = (position + shift) % 95
chr()
to change the integer value into the ASCII equivalent.new_char = chr(position + ord(" "))
encrypted_message += new_char
"""
Written by: Nabroleonx July 14,2021
Description: Caesar cipher encoder/decoder
"""
print('''
-------------------------------------------------------------
To decrypt what you encrypted,use the negative of the shift
value you entered to encrypt your message.
If you used a shift value of "3" to encrypt your message,
then use -3 to decrypt your message.
------------------------------------------------------------
''')
stop = 'no'
def cipher(message, shift):
encrypted_message = ""
for char in message:
if char >= " " and char <= "~":
position = ord(char) - ord(" ")
position = (position + shift) % 95
new_char = chr(position + ord(" "))
encrypted_message += new_char
print("The encrypted message is: ", encrypted_message)
while stop == 'no':
message = input("Enter the message you want to encrypt/decrypt: ")
shift = int(input("enter the shift value u want: "))
cipher(message, shift)
again = input("do you want to continue? yes/no ").lower()
if again == 'yes':
continue
else:
print("\n Thanks for using me! Till next time, Cya")
stop = 'yes'