python ascii caesar cipher
def ascii_caesar_shift(message, distance):
encrypted = ""
for char in message:
value = ord(char) + distance
encrypted += chr(value % 128) #128 for ASCII
return encrypted
python ascii caesar cipher
def ascii_caesar_shift(message, distance):
encrypted = ""
for char in message:
value = ord(char) + distance
encrypted += chr(value % 128) #128 for ASCII
return encrypted
python caesar cipher
plaintext = input("Please enter your plaintext: ")
shift = input("Please enter your key: ")
alphabet = "abcdefghijklmnopqrstuvwxyz"
ciphertext = ""
# shift value can only be an integer
while isinstance(int(shift), int) == False:
# asking the user to reenter the shift value
shift = input("Please enter your key (integers only!): ")
shift = int(shift)
new_ind = 0 # this value will be changed later
for i in plaintext:
if i.lower() in alphabet:
new_ind = alphabet.index(i) + shift
ciphertext += alphabet[new_ind % 26]
else:
ciphertext += i
print("The ciphertext is: " + ciphertext)
caesar cipher python
def cc_encrypt(msg: str,key: int) -> str:
encrypted_msg = ''
try:
for char in msg:
encrypted_msg += str(chr(ord(char)+int(key)))
except:
print(Exception)
pass
return encrypted_msg
def cc_decrypt(msg: str,key: int) -> str:
decrypted_msg = ''
try:
for char in msg:
decrypted_msg += chr(ord(char)-int(key))
except:
print(Exception)
pass
return decrypted_msg
message = 'Hello World!'
key = 9
print(f'Caesar Cipher:nEncrypted: {cc_encrypt(message,key)}nDecrypted: {cc_decrypt(cc_encrypt(message,key),key)}')
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us