def dec_msg(key_store, message_buffer): txt_msg = "" try: txt_msg = onetimepad.decrypt(message_buffer, key_store) except: txt_msg = "" return txt_msg
def main(): with CQCConnection("Alice") as Alice: #msg="Hello" #alic.send_QOTP_msg(msg) #k=alic.BB84_key() #log keys while True: #alic=BB84_Sender(cqc_sender=Alice,receiver="Bob",hacker="Eve") alic = BB84_Sender(cqc_sender=Alice, receiver="Bob") key = alic.BB84_key() msq = input('Alice ->') if msq == "exit": exit() cipher = otp.encrypt(msq, key) Alice.sendClassical("Bob", bytes(cipher.encode())) cipher2 = Alice.recvClassical() print("cipher received ", cipher2) plain = otp.decrypt(cipher2.decode(), key) print("Msg Received from Bob-> ", plain) time.sleep(5) Alice.close()
def Decrypt(): file = open('encryptedmsg.txt', "r") decrypt = otp.decrypt(str(file.read()), e4.get()) temp = str(decrypt) #Label(top, text = "Message is "+temp, fg="black").place(x=150, y=150) messagebox.showinfo("Message", temp) file.close()
def dycrptMessage(): a = var2.get() ct = onetimepad.decrypt(a, "saikumar") print("Working", ct) e4.delete(0, END) e4.insert(END, ct)
def encode_decode(self, source, my_key): soc = socket.socket(socket.AF_INET, socket.SOCK_STREAM) soc.bind(('127.0.0.1', 3036)) soc.listen(5) print('Listening at', soc.getsockname()) flag = True while True: sc, address = soc.accept() print('We have accepted a connection from', address) print(' Socket name:', sc.getsockname()) message = recv_all(sc, 1024) obj = pickle.loads(message) text = obj.data key = obj.json if(flag): print('Plain text is ', text) cipher = onetimepad.encrypt( text, key) print("Cipher text is", repr(cipher)) sc.sendall(cipher.encode('utf-8')) else: print("Cipher text is ", text) plain = onetimepad.decrypt( text, key) print("Plain text is", repr(plain)) sc.sendall(plain.encode('utf-8')) sc.close() flag = not flag
def index(request): data = dict() affine = Affine() if request.method == 'POST': procedure = request.POST.get('procedure', None) method = request.POST.get('method', None) text = request.POST.get('message', None) if procedure and method and text: if procedure.lower() == 'encrypt'.lower(): if method.lower() == 'affine'.lower(): result = affine.encrypt(text) elif method.lower() == 'onetime'.lower(): result = onetimepad.encrypt(text, 'random') elif procedure.lower() == 'decrypt'.lower(): if method.lower() == 'affine'.lower(): result = affine.decrypt(text) elif method.lower() == 'onetime'.lower(): result = onetimepad.decrypt(text, 'random') data.update({'result': result}) else: data.update({'error': 'Please fill all the details!!'}) return render(request, 'index.html', data) else: return render(request, 'index.html', data)
def decrypt_message(self, message): try: msg = onetimepad.decrypt(message, self._key) return msg except Exception as x: print_data(x)
def login(request): if request.session.has_key('username'): username = request.session['username'] return redirect(index, username) elif request.method == "POST": email_id = request.POST['email_id'] password = request.POST['password'] try: user = UserDetail.objects.get(email_id=email_id) except: user = None if user is None: messages.info(request, "Email ID and Password is Incorrect") return redirect(signUp) else: if user.email_id == email_id and onetimepad.decrypt( user.password, 'password') == password: request.session['username'] = user.username messages.success(request, "Login Successfully") return redirect(index, user.username) else: messages.info( request, "Username and Password Combination is Incorrect") return redirect(signUp) return render(request, 'login.html', {})
def encrypted(request): params = {} if 'Generate' in request.POST: generate = onetimepad.encrypt(request.POST['encrypt'], 'random') # convert(generate) params['key'] = generate elif 'Convert' in request.POST: convert = onetimepad.decrypt(request.POST['decrypt'], 'random') params['new'] = convert return render(request, 'Encrypting_Decrypting.html', params)
async def decrypt(self, ctx, *, text: str): msg = onetimepad.decrypt(text, 'a_random_key') gemb = discord.Embed(title='Decryption', color=self.bot.embed_color, timestamp=ctx.message.created_at).set_footer( text=f"Requested by {ctx.author}", icon_url=ctx.author.avatar_url) gemb.add_field(name='Input:', value=f'```\n{text}\n```') gemb.add_field(name='Output:', value=f'```\n{msg}\n```', inline=False) await ctx.send(embed=gemb)
def decodeCredentials(self, json_creds): try: with open(KEY_PATH, 'r') as f: s = f.readline() screds = decrypt(json_creds, s) jcreds = json.loads(screds) creds = Credentials(**jcreds) return creds except Exception as e: raise Exception( f"Error in CalendarAPI.py: decodeCredentials(): {str(e)}")
def OneTimePad(plaintext): key = "" words = [["Two", "Three", "Four"], ["red", "yellow", "green"], ["cats", "dogs", "zebras"], ["jumped.", "danced.", "wrote_poetry."]] key = "".join([random.choice(w) for w in words]) cipher = onetimepad.encrypt(plaintext, key) msg = onetimepad.decrypt(cipher, key) return msg, key, cipher
def download2(): searchfiles() key = request.form['k1'] print('key', key) print('key1', key1) if key == str(key1): file = onetimepad.decrypt(encfile.decode(), 'random') print("File Content", file) file1 = open('f:\\dataleakage\\target\\' + fname + ".txt", 'w') file1.write(str(file)) file1.close() return render_template("success.html", msg='success') return render_template("Failure.html", msg='Failure')
def decrypter(self , stringToDecrypt): self.checkIfPossible() # getting the key newKey = onetimepad.decrypt(stringToDecrypt[:88] , self.__convPass) # conv strings to bytes key = bytes(newKey , "utf-8") cipher_suite = Fernet(key) decoded_text = cipher_suite.decrypt(bytes(stringToDecrypt[88:] , "utf-8")) return decoded_text.decode("utf-8")
def show(name): if Task.check(name) == False: #if task list is empty print('No tasks in the to-do list!\n') else: file = open('./to-do-list/{}.txt'.format(name), 'r') obj = file.read().splitlines() password = udb.User.crypt_key(name) for i in range(len(obj)): obj[i] = ot.decrypt(obj[i], password) #decrypt the contents of task print('---> ' + str(i + 1) + '. ' + obj[i] + '\n') #prints tasks one by one
def decryptThing(self, thing, key): try: stringToReturn = onetimepad.decrypt(thing, key) self.cLog.log( "decrypting thing func runned successfully in main for password", "i") return str(stringToReturn) except Exception as e: # if(self.cLog.troubleShoot == False): # print("\nSomething went wrong while decrypting, Please Try again, if error persist, run troubleShoot command") # else: # print("\nerror has been logged - continue...") # input("press enter to continue...") self.cLog.log("error while decrypting in main for password", "e") self.cLog.exception(str(e), "mainForPassword.py/decryptingThing")
def show(name, name_of_note): #if there is no folder, create one if os.path.isfile('./notes/{}/{}.txt'.format(name, name_of_note)) == False: print('Note not found\n') #if folder is empty elif os.listdir('./notes/{}'.format(name)) == []: print('You have no notes!\n') else: file = open('./notes/{}/{}.txt'.format(name, name_of_note), 'r') password = udb.User.crypt_key(name) obj = file.read().strip() obj = ot.decrypt(obj, password) #decrypt contents of the note print(obj)
def noteToSpeech(name, name_of_note): #setup python text-to-speech engine = pyttsx3.init() engine.setProperty('rate', 150) if os.path.isfile('./notes/{}/{}.txt'.format(name, name_of_note)) == False: #if task list is empty engine.say('Note not found!') engine.runAndWait() else: file = open('./notes/{}/{}.txt'.format(name, name_of_note), 'r') obj = file.read().strip() password = udb.User.crypt_key(name) obj = ot.decrypt(obj, password) #decrypt contents of note engine.say(obj) engine.runAndWait()
def taskToSpeech(name): #setup python text-to-speech engine = pyttsx3.init() engine.setProperty('rate', 150) if Task.check(name) == False: #if task list is empty engine.say('No tasks in the to-do list!') engine.runAndWait() else: file = open('./to-do-list/{}.txt'.format(name), 'r') obj = file.read().splitlines() password = udb.User.crypt_key(name) for i in obj: i = ot.decrypt(i, password) #decrypt the task engine.say(i) engine.runAndWait()
def decrypt(): k = 0 ciphertext = pyperclip.paste() plaintext = half_decrypt_loop(ciphertext) print(f'\nEncoded Message: \033[93m{plaintext}\033[00m') counter = int(plaintext[-5:-1]) with open('key.txt') as get_key: for i in get_key: if k == counter: key = i k += 1 new_counter = str(counter + 1) with open('kcounter.txt', 'a+') as append_counter: append_counter.write(f'\n{new_counter}') placeholder = append_counter.read() plaintext = plaintext[0:len(plaintext) - 5] plaintext = onetimepad.decrypt(plaintext, key) print(f'\nDecoded Message: \033[92m{plaintext}\033[00m')
def main(): with CQCConnection("Bob") as Bob: #live encrypted chat while True: time.sleep(3) print("*******BB84 Protocol***********") Bo = BB84_Receiver(cqc_receiver=Bob, sender="Alice") key = Bo.BB84_key() print("key", key) cipher = Bob.recvClassical() time.sleep(1) print("cipher received ", cipher) plain = otp.decrypt(cipher.decode(), key) print("Msg Received from Alice-> ", plain) msq = input('Bob ->') cipher = otp.encrypt(msq, key) Bob.sendClassical("Alice", bytes(cipher.encode())) Bob.close()
import onetimepad cipher = onetimepad.encrypt('One Time Cipher', 'random') print('Cipher text is ') print(cipher) print('Plain text is ') msg = onetimepad.decrypt(cipher, 'random') print(msg)
def decrypt(self,m): return onetimepad.decrypt(m,self.__key.decode("ISO-8859-5"))
def DecryptONETIME(text, key): return onetimepad.decrypt(text,key)
def decrypted_text(username, cipher_txt): text = onetimepad.decrypt(cipher_txt, username) return text
def decrypt_password(encrypted_password): return onetimepad.decrypt(encrypted_password, context.user_password)
async def decrypt(ctx, cipher, key): try: cipher = onetimepad.decrypt(cipher, key) await ctx.send("```DECRYPTED MESSAGE: \n" + cipher + "```") except: await ctx.send("izzy fix ur code it ran an error")
def decrypt(encrypted_data): return onetimepad.decrypt(encrypted_data, key)
def odecrypt(string, key): cipher = onetimepad.decrypt(string, key) print("The Decoded message is ") return cipher
def decryptMessage(): ct1 = e3.get() # inbuilt function to decrypt a message pt1 = onetimepad.decrypt(ct1, 'random') e4.insert(0, pt1)