Hey, I need help with programming this certain bit of code. I literally just started using Python a few months ago and am a novice at this. This is the description of the challenge:
A more secure method of encryption would be to use a keyword. A keyword is the information needed in order to transform the plaintext into the encrypted message and is also used by the recipient to decrypt the message. For example, a keyword could be the letters GCSE. The keyword is repeated enough times to match the length of the plaintext message. The alphabet value (position of the letter in the alphabet) of each letter of the key phrase is added to the alphabet value of each letter of the plaintext message to generate the encrypted text.
For example, if we use the keyword GCSE then we make up the key phrase for COMPUTINGISFUN by repeating the letters within GCSE to make a 14 letter code, GCSEGCSEGCSEGC, where G is the 7th letter of the alphabet, C the 3rd, S the 19th and E the 5th.
This is the code I have already:
message = input('Please type your message :')
keyword = input('Please type your keyword :')
finalEncrypt = ""
keywordPosition = 0
for currentLetter in message:
alphabetPosition = ord(currentLetter) #alphabetPosition if I type a C will = 67
newAlphPos = (alphabetPosition) - 64
total = (keywordLetter) + (newAlphPos)
keywordLetter = ord(keyword) -64
key = keyword[0+keywordPosition]
if total > 26:
(total) -26
encryptedLetter = chr(total +64)
finalEncrypt = finalEncrypt + (encryptedLetter)
newAlphPos = (keywordPosition) +1
if keywordPosition == currentLetter:
keywordPosition = ord(message) -64
#for i in range (1,2):
print(finalEncrypt)
What am I doing wrong? Where am I missing code? Am I on the right lines? Help
A more secure method of encryption would be to use a keyword. A keyword is the information needed in order to transform the plaintext into the encrypted message and is also used by the recipient to decrypt the message. For example, a keyword could be the letters GCSE. The keyword is repeated enough times to match the length of the plaintext message. The alphabet value (position of the letter in the alphabet) of each letter of the key phrase is added to the alphabet value of each letter of the plaintext message to generate the encrypted text.
For example, if we use the keyword GCSE then we make up the key phrase for COMPUTINGISFUN by repeating the letters within GCSE to make a 14 letter code, GCSEGCSEGCSEGC, where G is the 7th letter of the alphabet, C the 3rd, S the 19th and E the 5th.
This is the code I have already:
message = input('Please type your message :')
keyword = input('Please type your keyword :')
finalEncrypt = ""
keywordPosition = 0
for currentLetter in message:
alphabetPosition = ord(currentLetter) #alphabetPosition if I type a C will = 67
newAlphPos = (alphabetPosition) - 64
total = (keywordLetter) + (newAlphPos)
keywordLetter = ord(keyword) -64
key = keyword[0+keywordPosition]
if total > 26:
(total) -26
encryptedLetter = chr(total +64)
finalEncrypt = finalEncrypt + (encryptedLetter)
newAlphPos = (keywordPosition) +1
if keywordPosition == currentLetter:
keywordPosition = ord(message) -64
#for i in range (1,2):
print(finalEncrypt)
What am I doing wrong? Where am I missing code? Am I on the right lines? Help
