def TestDecryptEmpty(): """ Test decrypt function for empty cipherfile """ expected = "" encrypt("asdqwqweqqa", "decryptEmptyC.txt", "decryptEmptyP.txt") with open("decryptEmptyP.txt", 'rb') as myfile: result = myfile.read() print "Expected: " + expected print "Result: " + result assert result == expected
def TestEncryptEmpty(): """ Test encrypt function for empty plainfile """ expected = "" encrypt("asdqwqweqqa", "encryptEmptyP.txt", "encryptEmptyC.txt") with open('encryptEmptyC.txt', 'rb') as myfile: result = myfile.read() print "Expected: " + expected print "Result: " + result assert result == expected
def TestEncryptMultipleWords(): """ Test encrypt with long key and multiple words then compare with the hexadecimal decrypted result from RC4 Wiki [Links provided in at the top] """ expected = "45A01F645FC35B383552544B9BF5" encrypt("Secret", "encryptMultipleP.txt", "encryptMultipleC.txt") with open("encryptMultipleC.txt", "rb") as myfile: result = myfile.read().encode("hex").upper() print "Expected: " + expected print "Result: " + result assert result == expected
def TestEncryptLong(): """ Test encrypt with a longer key and compare with the hexadecimal decrypted result from RC4 Wiki [Links provided in at the top] """ expected = "1021BF0420" encrypt("Wiki", "encryptLongP.txt", "encryptLongC.txt") with open("encryptLongC.txt", "rb") as myfile: result = myfile.read().encode("hex").upper() print "Expected: " + expected print "Result: " + result assert result == expected
def TestEncryptSmall(): """ Test encrypt with small key and compare with the hexadecimal decrypted result from RC4 Wiki [Links provided in at the top] """ expected = "BBF316E8D940AF0AD3" encrypt("Key", "encryptSmallP.txt", "encryptSmallC.txt") with open("encryptSmallC.txt", "rb") as myfile: result = myfile.read().encode("hex").upper() print "Expected: " + expected print "Result: " + result assert result == expected
def main(): message = clip.paste() if not message: return message = rc4.encrypt(message.encode('utf-8'), config.password) thunks = [ message[i:i + MESSAGE_SIZE] for i in range(0, len(message), MESSAGE_SIZE) ] thunk_count = len(thunks) my_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) my_socket.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) for i, thunk in enumerate(thunks): msg = { 'username': config.username, 'node': platform.node(), 'order': i, 'msg': thunk } if i == 0: msg['first'] = True if i + 1 == thunk_count: msg['last'] = True msg = json.dumps(msg) # print 'Length of message is %d.' % len(msg) my_socket.sendto(msg, (config.broadcast_network, config.port)) my_socket.close()
def Network_Auth(): url = "http://1.1.1.3/ac_portal/login.php" #构建POST包 #js加密方式:userName=明文;pwd=rc4加密(rc4Key,用户密码);rc4Key=当前时间13位时间戳 data = { "opr": "pwdLogin", "userName": "", "pwd": "", "auth_tag": "", "rememberPwd": "1" } f = open('profile.ini') #读配置文件 f1 = f.read() f1 = json.loads(f1) #用json方法字符串转字典 profile_passwd = f1["password"] #profile的用户名 now_date = str(int(round(time.time() * 1000))) #获取当前时间 secert_pass = rc4.encrypt(now_date, profile_passwd) #rc4加密 #写回到data字典中 data['userName'] = f1["username"] data['pwd'] = secert_pass data['auth_tag'] = now_date print(data) try: r = requests.post(url, data) except: return None else: login_status = r.text # 返回的是HTTP响应包 #print(login_status) return login_status
def send_message(self): """ Catches the returned encrypted message and sends it to the recipient then closes socket """ encrypt_mess = rc4.encrypt(self.message, self.key) print "Sending message..." self.client_sock.send(encrypt_mess) print "Sent encrypted message!" self.close_client()
def main(): key = 'mitre' message = 'the quick brown fox lept over the lazy dog' key_array = rc4.key_schedule(key) keystream = rc4.get_keyStream(key_array, len(message)) ciphertext = rc4.encrypt(message, keystream) outfile = open('out.txt', 'w') alphabet = [chr(x) for x in range(97, 123)] for l1 in alphabet: print l1, for l2 in alphabet: for l3 in alphabet: for l4 in alphabet: for l5 in alphabet: key = l1 + l2 + l3 + l4 + l5 jobs.append( jobServer.submit(try_combo, (key, ciphertext, outfile), (decrypt, key_schedule, get_keyStream)) ) print('Jobs added. Completing Jobs') for job in jobs: job() jobServer.get_stats() jobServer.print_stats()
def encrypt_and_put(password, key): """Encrypts and puts the password in the db but the original remains unaltered""" backup = copy.copy(password.strong) for i in range(len(password.strong)): password.strong[i] = rc4.encrypt(password.strong[i], key) password.encrypted = True password.put() password.strong = backup
async def _producer_handler(ws, key): global inc1 inc1 += 1 plaintext = str(inc1) + " testing hello friend :)" if ENCRYPTION: ciphertext = rc4.encrypt(key, plaintext) else: ciphertext = plaintext await ws.send(ciphertext) await asyncio.sleep(.1)
def encrypt_data(key, data, algorithm="rc4", use_custom_rc4=False): """ Encrypts data with key and specified algorithm. """ if algorithm == "rc4": return rc4.encrypt(key, data, use_custom_rc4) elif algorithm == "rc5": cryptor = RC5(key) cryptor.mode = "CBC" return cryptor.encrypt(bytes(data))
def encrypt_packets(packets): ''' Encrypt given list of packets ''' count = 0 encrypted_packets = [] flag = 'kingand queen' for packet in packets: init_vector = '%03d' % (count % 1000) key = init_vector + flag key_array = rc4.key_schedule(key) keystream = rc4.get_keyStream(key_array, len(packet)) encrypted_packet = init_vector + rc4.encrypt(packet, keystream) encrypted_packets.append(encrypted_packet) count += 1 return encrypted_packets
def login(): user = "******" #用户名 pswd = "Az123456!" #密码 url = "http://1.1.1.3/ac_portal/login.php" data = { "opr": "pwdLogin", "userName": "", "pwd": "", "auth_tag": "", "rememberPwd": "1" } now_date = str(int(round(time.time() * 1000))) password = rc4.encrypt(now_date, pswd) data['userName'] = user data['pwd'] = password data['auth_tag'] = now_date requests.post(url, data)
def encrypt_RC4(): start_time = time() global ciphertext_rc4 global ciphertext_rc4_in_str print("Normal Message : ", normal_message) msg = normal_message key = rc4_key.get() print("Key : ", key) ciphertext_rc4 = encrypt(msg, key) ciphertext_rc4_in_str = bytes.decode(ciphertext_rc4) print("Cipher Message : ", ciphertext_rc4_in_str) output_rc4.insert(tk.END, "%s" % (ciphertext_rc4_in_str)) end_time = time() time_taken = end_time - start_time hours, rest = divmod(time_taken, 3600) minutes, seconds = divmod(rest, 60) print("Time taken : ", format_timespan(end_time - start_time)) messagebox.showinfo("Success!", "Encrypt RC4 Success")
def encrypt_AES(): start_time = time() global ciphertext_aes global ciphertext_aes_in_str print("Cipher Message : ", cipher_rc4_msg) msg_aes = cipher_rc4_msg key = aes_key.get() print("Key : ", key) ciphertext_aes = encrypt(msg_aes, key) ciphertext_aes_in_str = bytes.decode(ciphertext_aes) print("Cipher Message : ", ciphertext_aes_in_str) output_aes.insert(tk.END, "%s" % (ciphertext_aes_in_str)) end_time = time() time_taken = end_time - start_time hours, rest = divmod(time_taken, 3600) minutes, seconds = divmod(rest, 60) print("Time taken : ", format_timespan(end_time - start_time)) messagebox.showinfo("Success!", "Encrypt AES Success")
def main(): message = clip.paste() if not message: return message = rc4.encrypt(message.encode('utf-8'), config.password) thunks = [message[i:i+MESSAGE_SIZE] for i in range(0, len(message), MESSAGE_SIZE)] thunk_count = len(thunks) my_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) my_socket.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST,1) for i, thunk in enumerate(thunks): msg = {'username': config.username, 'node': platform.node(), 'order': i, 'msg': thunk} if i == 0: msg['first'] = True if i + 1 == thunk_count: msg['last'] = True msg = json.dumps(msg) # print 'Length of message is %d.' % len(msg) my_socket.sendto(msg, (config.broadcast_network, config.port)) my_socket.close()
def Client(clientsocket, name, host, port, buf): host = socket.gethostbyname(host) #Get Host IP/DNS clientaddr = (host, port) try: clientsocket.connect(clientaddr) #Connect to Recipient's Server message = MultiLineMessage() #Write Message #Format data as per TauNet Protocol message = "version: {}\r\nfrom: {}\r\nto: {}\r\n\r\n{}\r\n".format( variables.version, variables.username, name, message) #Encrypt data usign RC4 message = rc4.encrypt(message, variables.rounds, variables.key) clientsocket.send(message) #Send message except socket.error: #Failed to connect print("Cannot send message") clientsocket.close() #Close connection
def _step6_get_code(self, verhoeff, base64_string): seed = self.get_secret() + verhoeff return rc4.encrypt(base64_string, seed)
def _step3_encode_allegedrc4(self, verhoeff, long_string): seed = self.get_secret() + verhoeff return rc4.encrypt(long_string, seed)
def test_wave_encrypt(): rc4.encrypt("Moon", "neil.wav", "result.wav") # neilc.wav is verified to be correct assert(filecmp.cmp('neilc.wav', 'result.wav'))
def test_encrypt(): rc4.encrypt("Key", "plainfile.txt", "result.txt") # cipherfile.txt is verified to be correct assert(filecmp.cmp('cipherfile.txt', 'result.txt'))
def oracle(request): key = os.urandom(16) return encrypt(key, request + secret)
def get(self): data = self.request.get('data').encode('utf-8') data = simplejson.loads(data) weak = data['weak'] key = weak.encode('ascii', 'replace') weak_hash = hashlib.sha224(key).hexdigest() charset = PASSWORD_SET options = dict() options['uppercase'] = options['lowercase'] = options['numeric'] = True options['special'] = False if data['chars']: options = data['chars'] if options['uppercase'] or options['lowercase'] or options['numeric'] or options['special']: charset = '' if options['uppercase']: charset += string.ascii_uppercase if options['lowercase']: charset += string.ascii_lowercase if options['numeric']: charset += string.digits if options['special']: charset += "!#$%&'()*+,-./:;=?@[\]^_`{|}~" else: options['uppercase'] = options['lowercase'] = options['numeric'] = True options['special'] = False password = Password.all() password = password.filter('weak =', weak_hash) password = password.filter('lowercase =',options['lowercase']) password = password.filter('uppercase =',options['uppercase']) password = password.filter('digits =',options['numeric']) password = password.filter('special =',options['special']) password = password.get() if not password: randoms = get_random_passwords(n=PASSWORD_NUMBER, len=PASSWORD_LENGTH, set=charset) password = Password( weak = weak_hash, uppercase = options['uppercase'], lowercase = options['lowercase'], digits = options['numeric'], special = options['special'] ) for r in randoms: r = rc4.encrypt(r,key) password.strong.append(r) password.encrypted = True password.put() if password.encrypted == True: for i in range(len(password.strong)): password.strong[i] = rc4.decrypt(password.strong[i], key) else: encrypt_and_put(password, key) # Integrate old passwords if len(password.strong) is 0: merge_old_passwords(password, charset) encrypt_and_put(password, key) # if the PASSWORD_NUMBER has been altered if len(password.strong) < PASSWORD_NUMBER: fill_up_password_number(password, charset) encrypt_and_put(password, key) if len(password.strong) > PASSWORD_NUMBER: password.strong = password.strong[:PASSWORD_NUMBER] # if the PASSWORD_LENGTH has been altered if len(password.strong[0]) < PASSWORD_LENGTH: fill_up_password_length(password, charset) encrypt_and_put(password, key) if len(password.strong[0]) > PASSWORD_LENGTH: for i in range(len(password.strong)): password.strong[i] = password.strong[i][:PASSWORD_LENGTH] # Encode using the GQL Encoder rest = list() for i in range(len(password.strong)): rest.append({'id': i, 'password': password.strong[i][:data['length']]}) data = simplejson.dumps(rest) self.response.headers['Content-Type'] = 'application/json; charset=utf-8' self.response.out.write(data)
def connectionMade(self): #self.transport.write("Hello, world!") gpsdata = "$GPGGA,184353.07,1929.045,S,02410.506,E,1,04,2.6,100.00,M,-33.9,M,,0000*6D" enc = encrypt(gpsdata, key) self.transport.write(enc)