Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- alphabet = "abcdefghijklmnopqrstuvwxyz"
- numbers = "1234567890"
- word = input("Enter the word you want me to cipher: ")
- offset = int(input("Enter offset (must be an integer): "))
- try:
- print()
- print("Before ciphering: " + word)
- list = [] # There, I will add the characters of the converted word
- for ch in word: # 1st scan: ch = each character of the variable "word"\
- counter = 0 # Create a counter: it will be used to count the FAILS in the
- # comparison between the "ch" and all the letters in "alphabet"
- for i in range(len(alphabet)): # 2nd scan: i = index in string "alphabet"
- if ch.lower() == alphabet[i]: # Here, I see if "ch" converted to lowerCase is equal to alphabet[i]
- if ch == ch.lower(): # If "ch" is lowerCase,
- list.append(alphabet[(i + offset) % (len(alphabet))]) #I add the appropriate letter in list
- break
- else: # If "ch" is upperCase,
- letter = alphabet[(i + offset) % (len(alphabet))] #I add the "letter" ("letter" is lowerCase) after I convert it into upperCase
- list.append(letter.upper())
- break
- elif i <= len(numbers)-1 and ch == numbers[i]: # If "ch" = numbers[i] and i <= 9 (avoid overflow)
- list.append(numbers[ (i + offset) % len(numbers) ])
- break
- elif ch == " ": # This is the case, when I find a "spacebar" character
- list.append(" ") # Malista, edw ekteleitai MONO mia fora h 2h for
- break
- else: # Here, the 2nd loop goes, when "ch" != alphabet[i] and "ch" != " "
- counter += 1 # I increase by 1 the counter in case of failure in comparison between ch and alphabet[i] or spacebar
- if counter == len(alphabet): # Gia na ftasei edw shmainei oti **DEN EGINE KANENA BREAK** kai episis o **counter = 26**, ara 26 failures ---> o "ch" einai kapoios allos character
- list.append(ch)
- print("After ciphering: " + ''.join(map(str, list)))
- except ValueError:
- print("Value Error!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement