Cita da
Gman su 22 Dicembre 2023, 13:06
Gentiluomini, chi trova e fixa il bug passa un Buon Natale:
# Double the given alphabet
def getDoubleAlphabet(alphabet):
doubleAlphabet = alphabet + alphabet
return doubleAlphabet
# Get a message to encrypt
def getMessage():
stringToEncrypt = input("Please enter a message to encrypt: ")
return stringToEncrypt
# Get a cipher key
def getCipherKey():
shiftAmount = input("Please enter a key (whole number from 1-25): ")
return shiftAmount
# Encrypt message
def encryptMessage(message, cipherKey, alphabet):
encryptedMessage = ""
uppercaseMessage = ""
uppercaseMessage = message.upper()
for currentCharacter in uppercaseMessage:
position = alphabet.find(currentCharacter)
newPosition = position + int(cipherKey)
if currentCharacter in alphabet:
encryptedMessage = encryptedMessage + alphabet[newPosition]
else:
encryptedMessage = encryptedMessage + currentCharacter
return encryptedMessage
# Decrypt message
def decryptMessage(message, cipherKey, alphabet):
decryptKey = -1 * int(cipherKey)
return encryptMessage(message, cipherKey, alphabet)
# Main program logic
def runCaesarCipherProgram():
myAlphabet="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
print(f'Alphabet: {myAlphabet}')
myAlphabet2 = getDoubleAlphabet(myAlphabet)
print(f'Alphabet2: {myAlphabet2}')
myMessage = getMessage()
print(myMessage)
myCipherKey = getCipherKey()
print(myCipherKey)
myEncryptedMessage = encryptMessage(myMessage, myCipherKey, myAlphabet2)
print(f'Encrypted Message: {myEncryptedMessage}')
myDecryptedMessage = decryptMessage(myEncryptedMessage, myCipherKey, myAlphabet2)
print(f'Decrypted Message: {myDecryptedMessage}')
# Main logic
runCaesarCipherProgram()
A dire il vero auguro di passare un Buon Natale a tutti i Gentiluomini, in particolare ai Moderatori,
che ci hanno dedicato parte del loro prezioso tempo e della loro energia.
Un abbraccio cari Gents, ci vediamo nel 2024!
Gentiluomini, chi trova e fixa il bug passa un Buon Natale:
# Double the given alphabet
def getDoubleAlphabet(alphabet):
doubleAlphabet = alphabet + alphabet
return doubleAlphabet
# Get a message to encrypt
def getMessage():
stringToEncrypt = input("Please enter a message to encrypt: ")
return stringToEncrypt
# Get a cipher key
def getCipherKey():
shiftAmount = input("Please enter a key (whole number from 1-25): ")
return shiftAmount
# Encrypt message
def encryptMessage(message, cipherKey, alphabet):
encryptedMessage = ""
uppercaseMessage = ""
uppercaseMessage = message.upper()
for currentCharacter in uppercaseMessage:
position = alphabet.find(currentCharacter)
newPosition = position + int(cipherKey)
if currentCharacter in alphabet:
encryptedMessage = encryptedMessage + alphabet[newPosition]
else:
encryptedMessage = encryptedMessage + currentCharacter
return encryptedMessage
# Decrypt message
def decryptMessage(message, cipherKey, alphabet):
decryptKey = -1 * int(cipherKey)
return encryptMessage(message, cipherKey, alphabet)
# Main program logic
def runCaesarCipherProgram():
myAlphabet="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
print(f'Alphabet: {myAlphabet}')
myAlphabet2 = getDoubleAlphabet(myAlphabet)
print(f'Alphabet2: {myAlphabet2}')
myMessage = getMessage()
print(myMessage)
myCipherKey = getCipherKey()
print(myCipherKey)
myEncryptedMessage = encryptMessage(myMessage, myCipherKey, myAlphabet2)
print(f'Encrypted Message: {myEncryptedMessage}')
myDecryptedMessage = decryptMessage(myEncryptedMessage, myCipherKey, myAlphabet2)
print(f'Decrypted Message: {myDecryptedMessage}')
# Main logic
runCaesarCipherProgram()
A dire il vero auguro di passare un Buon Natale a tutti i Gentiluomini, in particolare ai Moderatori,
che ci hanno dedicato parte del loro prezioso tempo e della loro energia.
Un abbraccio cari Gents, ci vediamo nel 2024!
MarsWalker and Kris have reacted to this post.