def encrypt(text, key): import string result = "" idx = 0 for char in text: result += rotate_character(char, alphabet_position(key[idx])) if char in string.ascii_letters: idx = (idx + 1) % len(key) return result
def encrypt(text, rot): encrypted_msg="" key_index=0 for i in range(len(text)): if text[i]==" " or not text[i].isalpha(): encrypted_msg+=text[i] else: encrypted_msg+=rotate_character(text[i],alphabet_position(rot[key_index%len(rot)])) key_index+=1 return encrypted_msg
def encrypt(text, key): new_string = "" key_index = -1 for idx in range(len(text)): if text[idx].isalpha(): key_index = (key_index + 1) % len(key) rot = alphabet_position(key[key_index]) new_string = new_string + rotate_character(text[idx], rot) else: new_string = new_string + text[idx] return new_string
def encrypt(text, key): newText = '' keyPosition = 0 for i in text: keyRot = alphabet_position(key[keyPosition]) newText += rotate_character(i, keyRot) if i.isalpha(): keyPosition += 1 if keyPosition == len(key): keyPosition = 0 return newText
def encrypt(text, key_word): encry_text = "" v = 0 for x in text: if x.isalpha(): y = alphabet_position(key_word[v % len(key_word)]) encry_text = encry_text + rotate_character(x, y) v = v + 1 else: encry_text = encry_text + x return encry_text
def main(): letter = input("Please type a letter ") print(alphabet_position(letter)) char = input("Please type a character ") rot = input("Rotate by: ") print(rotate_character(char, rot)) text = input("Please type some text ") rot = input("Rotate by: ") print(encrypt(text, rot))
def encrypt(text, encryption_key): counter = 0 new_text = [] for char in text: if char.isalpha(): if counter < len(encryption_key) - 1: new_text.append( caesar.encrypt( char, helpers.alphabet_position(encryption_key[counter]))) counter += 1 elif counter == len(encryption_key) - 1: new_text.append( caesar.encrypt( char, helpers.alphabet_position(encryption_key[counter]))) counter = 0 else: new_text.append(char) return "".join(new_text)
def encrypt(message, keyword): scrambled_text = '' letter = 0 for i in range(len(message)): if message[i].isalpha(): scrambled_text += rotate_character( message[i], alphabet_position(keyword[letter % len(keyword)])) letter += 1 else: scrambled_text += message[i] return scrambled_text
def encrypt(text, key): new_text = '' j = 0 for i in range(0, len(text), 1): if ord(text[i]) < ascii_A: new_text += text[i] else: new_text += rotate_character( text[i], alphabet_position(key[j % (len(key))])) j += 1 return new_text
def encrypt(sentence, word): idx = 0 new_sentence = "" for letter in sentence: if letter in alpha1 or letter in alpha2: if idx < len(word): rotate = alphabet_position(word[idx]) nl = rotate_character(letter, rotate) new_sentence = new_sentence + nl idx = idx + 1 else: idx = 0 rotate = alphabet_position(word[idx]) nl = rotate_character(letter, rotate) new_sentence = new_sentence + nl idx = idx + 1 else: new_sentence = new_sentence + letter return new_sentence
def encrypt(text, key): i = 0 key_mod = len(key) ciphertext = '' for char in text: if char.isalpha(): ciphertext += rotate_character(char, alphabet_position(key[i])) i = (i + 1) % key_mod else: ciphertext += char return ciphertext
def encrypt(text, key): cipher = '' l = len(key) idx = 0 for i in text: if i.isalpha(): cipher += rotate_character(i, alphabet_position(key[idx])) idx = (idx + 1) % l else: cipher += i return cipher
def encrypt(text, keyword): message = "" index = 0 for char in text: if char.isalpha(): rot = alphabet_position(keyword[index % len(keyword)]) message += rotate_character(char, rot) index += 1 else: message = message + char return message
def encrypt(text, key): encrypted = "" key_loc = 0 for char in text: if char.isalpha(): rot = alphabet_position(key[key_loc]) key_loc += 1 key_loc = key_loc % len(key) encrypted += rotate_character(char, rot) else: encrypted += char return encrypted
def encrypt(text, key): init = "" letter_in_keyword = 0 for i in range(len(text)): if text(i).isalpha(): init += rotate_character( text[i], alphabet_position(key[letter_in_keyword % len(key)])) letter_in_keyword += 1 else: init += text[i] return init
def encrypt(text, key): key_position = 0 new_text = "" for letter in text: rot = alphabet_position(key[key_position]) new_rot_char = rotate_character(letter, rot) new_text = new_text + new_rot_char if letter.isalpha(): key_position += 1 if len(key) == key_position: key_position = 0 return new_text
def encrypt(text, key): encrypted = '' counter = 0 i = 0 for letter in text: if letter.isalpha(): i = alphabet_position(key[counter]) encrypted = encrypted + rotate_character(letter, i) counter = ((counter + 1) % len(key)) else: encrypted = encrypted + letter return encrypted
def encrypt(text, word): ''' encrypts text ''' encrypted = '' count = 0 for char in text: if char.isalpha(): encrypted += rotate_character( char, alphabet_position(word[count % len(word)])) count += 1 else: encrypted += char return encrypted
def encrypt(text, key): index = 0 result = '' for char in text: if index > (len(key) - 1): index = 0 if char in sym: result += char else: result += rotate_character(char, alphabet_position(key[index])) index += 1 return result
def decrypt(ciphertext, key): i = 0 key_mod = len(key) original = '' for char in ciphertext: if char.isalpha(): original_shift = alphabet_position(key[i]) original += rotate_character(char, -original_shift) i = (i + 1) % key_mod else: original += char return original
def encrypt(msg, key): x = 0 new_msg = "" new_char = "" for letter in msg: new_char = rotate_character(letter, alphabet_position(key[x])) if new_char.isalpha(): x += 1 if x > len(key) - 1: x = 0 new_msg = new_msg + new_char return new_msg
def encrypt(text, cipher): encrypt_text = '' rotated_index = 0 for i in text: if i.isalpha(): w = alphabet_position(cipher[rotated_index % len(cipher)]) encrypt_text = encrypt_text + rotate_character(i, w) #can't convert int to str rotated_index = rotated_index + 1 else: encrypt_text = encrypt_text + rotate_character(i, w) return encrypt_text
def encrypt(plaintext, key): output = '' key_index = 0 for char in plaintext: if char.isalpha(): output += rotate_character(char, alphabet_position(key[key_index])) key_index = (key_index + 1) % len(key) else: output += char return output
def tests(): # Test alphabet_position() print(alphabet_position("A")) print(alphabet_position("a")) print(alphabet_position("x")) print(alphabet_position("z")) # test rotate_character() print(rotate_character("A", 13)) print(rotate_character("a", 13)) print(rotate_character("A", 130)) print(rotate_character("A", 26)) print(rotate_character("X", 13)) print(rotate_character("x", 13)) print(rotate_character("g", 10)) print(rotate_character("!", 27)) # test encrypt() print(encrypt("a", 13)) print(encrypt("abcd", 13)) print(encrypt("LaunchCode", 13)) print(encrypt("LaunchCode", 1)) print(encrypt("Hello, World!", 5))
def encrypt(text, key): startingIndex = 0 encrypted = [] for letter in text: if letter.isalpha() == True: rotation = alphabet_position(key[startingIndex % len(key)]) encrypted.append(rotate_character(letter, rotation)) startingIndex += 1 else: encrypted.append(letter) return ''.join(encrypted)
def encrypt(text, rot): '''Vigenere cipher, this program will behave like this: $ python vigenere.py Type a message: The crow flies at midnight! Encryption key: boom Uvs osck rmwse bh auebwsih! ''' new_str = "" ind_key = 0 for symbol in text: if (alphabet_position(symbol) != -1): # make sure the symbol is a characte new_let = rotate_character(symbol, alphabet_position(rot[ind_key])) new_str += new_let ind_key += 1 if ind_key >= len(rot): ind_key = 0 else: new_str += symbol return new_str
def encrypt(bullshit, rot): new_word = [] for x in bullshit: if x.isalpha() and x.islower(): if alphabet_position(x) + int(rot) < 26: new_position = alphabet_position(x) + int(rot) else: new_position = (alphabet_position(x) + int(rot)) - 26 aleph = alphabet[new_position] new_word.append(aleph) elif x.isalpha() and x.isupper(): if alphabet_position(x) + int(rot) < 26: new_position = alphabet_position(x) + int(rot) else: new_position = (alphabet_position(x) + int(rot)) - 26 aleph = alphabet[new_position].upper() new_word.append(aleph) else: new_word.append(x) print("".join(new_word)) return ("".join(new_word))
def encrypt(message,code): code_length = len(code) code_index = 0 rotated_text = [] text = list(message) for item in range(len(text)): if code_index < code_length : if text[item] == ' ' or text[item].isalpha() == False: rotated_text.append(text[item]) else: rot = alphabet_position(code[code_index]) rotated_text.append(rotate_character(text[item], int(rot))) code_index += 1 elif code_index == code_length : if text[item] == ' ' or text[item].isalpha() == False: rotated_text.append(text[item]) else: code_index = 0 rot = alphabet_position(code[code_index]) rotated_text.append(rotate_character(text[item], int(rot))) code_index += 1 return(''.join(rotated_text))
def new_encrypt(text, rot): new_text = '' rot_letter = 0 for char in text: start = rot[rot_letter] rotation_amount = alphabet_position(start) new_text += rotate_character(char, rotation_amount) if char.isalpha(): rot_letter += 1 if rot_letter >= len(rot): rot_letter = 0 return new_text
def encrypt(msg, key): """encrypt message with key""" key_pos_list = [] new_msg = "" num = 0 for char in key: key_pos_list.append(alphabet_position(char)) for char in msg: new_msg += rotate_character(char, (key_pos_list[num % len(key_pos_list)])) if char.isalpha(): num += 1 return new_msg