Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import math
- alphabet = "abcdefghijklmnopqrstuvwxyz"
- print()
- print("Enter a message below to cipher it: ")
- message = input("Message here: ")
- # CONVERT my message = STRING ----> LIST
- messageList = []
- for i in range(len(message)):
- messageList.append(message[i])
- print(messageList)
- # Copy messageList to initialMessageList
- initialMessageList = messageList.copy()
- # I will work with messageList to make the changes to my messsage
- # 1st step: REVERSE MY LIST
- for i in range(int(len(messageList)/2)): # Scan the half list and reverse it
- temp = messageList[i] # Swap method for elements in list
- messageList[i] = messageList[len(messageList) - 1 - i]
- messageList[len(messageList) - 1 - i] = temp
- # OR: messageList.reverse()
- reversedList = messageList.copy() # I keep the reversed messageList in the variable reversedList
- print(reversedList)
- # 2nd step: ATBAS SESSION
- # I will create another list to add the elements that I have from Atbas Code
- atbasList = []
- for ch in messageList: # ch = a character from the messageList
- for i in range(len(alphabet)): # I scan the alphabet in order to find my "ch" character
- if ch == alphabet[i]:
- atbasList.append(alphabet[len(alphabet) - 1 - i]) # In case of equality ----> I add in atbasList the appropriate letter
- break
- print(atbasList)
- '''
- My Lists now:
- 1) initialMessageList: Contains the letters of the given word
- 2) reversedList: Contains the letters of the given word, but in reversed form
- 3) atbasList: Contains the letters of the given word, in BUT REVERSED and ATBAS-ED form
- '''
- print()
- print("Message first: " + ''.join(map(str, initialMessageList)))
- print("Message after: " + ''.join(map(str, atbasList)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement