отправить сообщение """ vk.method('messages.send', {'peer_id' : id,'message' : text, 'random_id' : get_random_id()}) try: while True: messages = vk.method('messages.getConversations', {'offset': 0, 'count': 20, 'filter': 'unread'}) if messages['count'] > 0: id = messages['items'][0]['last_message']['from_id'] body = messages['items'][0]['last_message']['text'] # текст сообщения body = list(str(body.lower()).split()) if len(body) != 0: if body[0] in module.caesar: if len(body) > 3: try: if body[1] in module.cipher: send(caesar.cipher(str(body[3:]), int(body[2])), id) elif body[1] in module.decipher: send(caesar.decipher(str(body[3:]), int(body[2])), id) else: send(module.caesar_help, id) except: send(module.caesar_help, id) else: send(module.caesar_help, id) elif body[0] in module.cipher: send(module.caesar_help, id)
def decrypt(): message = request.args.get("message") if message: return cipher(message, SHIFT) return ""
def test_abcd(self): self.assertEqual(cipher(3, "abcd"), "defg")
def test_coding_type(self): result = cipher("e", "Aa. Bb!", 1) self.assertEqual(result, "Bb. Cc!") result = cipher("e", "Aa. Bb!", 10) self.assertEqual(result, "Kk. Ll!") result = cipher("d", "Aa. Bb!", 1) self.assertEqual(result, "Zz. Aa!") result = cipher("d", "Aa. Bb!", 10) self.assertEqual(result, "Qq. Rr!") result = cipher("", "Aa. Bb!", 10) self.assertEqual(result, "Function expects either command '-e' to encode or '-d' to decode") result = cipher(0, "Aa. Bb!", 10) self.assertEqual(result, "Function expects either command '-e' to encode or '-d' to decode") result = cipher(-1, "Aa. Bb!", 10) self.assertEqual(result, "Function expects either command '-e' to encode or '-d' to decode") result = cipher(0.532254654332, "Aa. Bb!", 10) self.assertEqual(result, "Function expects either command '-e' to encode or '-d' to decode") result = cipher("A string", "Aa. Bb!", 10) self.assertEqual(result, "Function expects either command '-e' to encode or '-d' to decode") result = cipher(False, "Aa. Bb!", 10) self.assertEqual(result, "Function expects either command '-e' to encode or '-d' to decode") result = cipher(True, "Aa. Bb!", 10) self.assertEqual(result, "Function expects either command '-e' to encode or '-d' to decode")
def test_user_key(self): result = cipher("e", "Aa. Bb!", 0) self.assertEqual(result, "user key must be an integer between 1 and 25") result = cipher("e", "Aa. Bb!", -1) self.assertEqual(result, "user key must be an integer between 1 and 25") result = cipher("e", "Aa. Bb!", 0.532254654332) self.assertEqual(result, "user key must be an integer between 1 and 25") result = cipher("e", "Aa. Bb!", 26) self.assertEqual(result, "user key must be an integer between 1 and 25") result = cipher("e", "Aa. Bb!", 2643254645865734532453264357533643513243543635748768745353242143234532566547456) self.assertEqual(result, "user key must be an integer between 1 and 25") result = cipher("e", "Aa. Bb!", "A string") self.assertEqual(result, "user key must be an integer between 1 and 25") result = cipher("e", "Aa. Bb!", "") self.assertEqual(result, "user key must be an integer between 1 and 25") result = cipher("e", "Aa. Bb!", False) self.assertEqual(result, "user key must be an integer between 1 and 25") result = cipher("e", "Aa. Bb!", True) self.assertEqual(result, "user key must be an integer between 1 and 25") result = cipher("d", "Aa. Bb!", 0) self.assertEqual(result, "user key must be an integer between 1 and 25") result = cipher("d", "Aa. Bb!", -1) self.assertEqual(result, "user key must be an integer between 1 and 25") result = cipher("d", "Aa. Bb!", 0.532254654332) self.assertEqual(result, "user key must be an integer between 1 and 25") result = cipher("d", "Aa. Bb!", 26) self.assertEqual(result, "user key must be an integer between 1 and 25") result = cipher("d", "Aa. Bb!", 2643254645865734532453264357533643513243543635748768745353242143234532566547456) self.assertEqual(result, "user key must be an integer between 1 and 25") result = cipher("d", "Aa. Bb!", "A string") self.assertEqual(result, "user key must be an integer between 1 and 25") result = cipher("d", "Aa. Bb!", "") self.assertEqual(result, "user key must be an integer between 1 and 25") result = cipher("d", "Aa. Bb!", False) self.assertEqual(result, "user key must be an integer between 1 and 25") result = cipher("d", "Aa. Bb!", True) self.assertEqual(result, "user key must be an integer between 1 and 25")
from caesar import cipher from art import logo from console import cls print(logo) direction_correct_inputs = ['e', 'd', 'encode', 'decode'] go = True while go: direction = input( "Type 'encode' to encode, type 'decode' to decode:\n").lower() if direction not in direction_correct_inputs: print("Please input e, encode, d, or decode") else: text = input("Type your message:\n") try: shift = int(input("Type the shift number:\n")) message = cipher(text, shift, direction) print(message) except ValueError: print("You can only shift by an integer value") restart = input("\n\nStart over (Y/N)?") if restart == "Y" or restart == "y": cls() else: go = False print("Well, hopefully it worked. Bye!")