def signUp(request): if request.session.has_key('username'): username = request.session['username'] return redirect(index, username) elif request.method == "POST": try: user = UserDetail.objects.get(email_id=request.POST['email_id']) except: user = None try: user = UserDetail.objects.get(username=request.POST['username']) except: user = None if user is not None: messages.info(request, "User with the Email ID is already exists") else: new_user = UserDetail() new_user.username = request.POST['username'] new_user.email_id = request.POST['email_id'] new_user.password = onetimepad.encrypt(request.POST['password'], 'password') new_user.confirm_password = onetimepad.encrypt( request.POST['confirm_password'], 'password') new_user.save() messages.success(request, "New User is Created Successfully") return render(request, 'signup.html', {})
def update(name, number, new_task): file = open('./to-do-list/{}.txt'.format(name), 'r') new_file = open('./to-do-list/new.txt', 'a') obj = file.read().splitlines() if int(number) > len(obj): #if the given number of task is not valid print('Task not found\n') else: for i in range(len(obj)): if i == int(number) - 1: password = udb.User.crypt_key(name) new_task = ot.encrypt( new_task, password) #encrypt the contents of task obj[i] = new_task new_file.write(obj[i] + '\n') else: new_file.write(obj[i] + '\n') file.close() new_file.close() os.remove('./to-do-list/{}.txt'.format(name)) os.rename('./to-do-list/new.txt', './to-do-list/{}.txt'.format(name)) udb.Logs.update_task(name, number) #update logs for user print('Task was successfully updated\n')
def encrypt(plaintext): print('\033[00m') k, counter = 0, '' with open('kcounter.txt') as get_counter: for i in get_counter: counter = i new_counter = str(int(counter) + 1) string_counter = counter.rjust(4, '0') with open('kcounter.txt', 'a+') as append_counter: append_counter.write(f'\n{new_counter}') placeholder = append_counter.read() with open('key.txt') as get_key: for i in get_key: if k == int(counter): key = i k += 1 plaintext = onetimepad.encrypt(plaintext, key) plaintext += string_counter + str(choice(range(9))) ciphertext = half_encrypt_loop(plaintext) print(f'Encoded Message: \033[93m{ciphertext}\033[00m') pyperclip.copy(ciphertext)
def enc_msg(key_store, message_buffer): cipher = "" try: cipher = onetimepad.encrypt(message_buffer, key_store) except: cipher = "" return cipher
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 encrypt_password(password): # We use the one time pad cipher with key as the user's master password # to encrypt the passwords stored in the database. # This cipher allows us to conveniently encrypt and decrypt, # as well as ensure that no one can gain access to the password # without the master password. return onetimepad.encrypt(password, context.user_password)
def encrypter(self , stringToEncrypt): self.checkIfPossible() stringToReturn = "" # key key = Fernet.generate_key() # conv key from bytes to str newKey = key.decode("utf-8") # encryting the key using the conv pass and keysalts keyToAdd = onetimepad.encrypt(newKey , self.__convPass) # conv string to bytes stringToPass = bytes(stringToEncrypt , "utf-8") cipher_suite = Fernet(key) encoded_text = cipher_suite.encrypt(stringToPass) stringToAdd = encoded_text.decode("utf-8") stringToReturn = keyToAdd + stringToAdd return stringToReturn
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 Encrypt(): messagebox.showinfo("Server Site", "Encrypted file is created") reader_file = open(str(e3.get()), "r") file = open("encryptedmsg.txt", "w") file.write(otp.encrypt(reader_file.read(), e4.get())) file.close() FILE_TRANSFER_SERVER2CLIENT()
def Encrypt(): messagebox.showinfo("Server Site", "Encrypted file is created") file = open("encryptedmsg.txt", "w") encrypt = otp.encrypt(e1.get(), e2.get()) file.write(encrypt) file.close() FILE_TRANSFER_SERVER2CLIENT()
def encrypt_message(self, message): try: ciphertext = onetimepad.encrypt(message, self._key) return ciphertext except Exception as x: raise x
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 encryptMessage(): a = var.get() ct = onetimepad.encrypt(a, "saikumar") print("Working", ct) e2.delete(0, END) e2.insert(END, ct)
async def encrypt(ctx, input): key = rstring(len(input) + 1) try: cipher = onetimepad.encrypt(input, key) await ctx.send( "```ENCRYPTED MESSAGE: \n" + cipher + "\nKEY:\n" + key + "```\nDon't lose your key, or you won't be able to decrypt it!") except: await ctx.send("Usage: -encrypt [message]")
def encodeCredentials(self, creds): try: jcreds = creds.to_json() with open(KEY_PATH, 'r') as f: s = f.readline() jcreds = encrypt(jcreds, s) return jcreds.encode() except Exception as e: raise Exception( f"Error in CalendarAPI.py: encodeCredentials(): {str(e)}")
def add(name, task): file = open('./to-do-list/{}.txt'.format(name), 'a') password = udb.User.crypt_key(name) task = ot.encrypt(task, password) #encrypt the content of task file.write(task + '\n') file.close() udb.Logs.add_task(name) #update logs of user print('Task was successfully added\n')
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)
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
async def encrypt(self, ctx, *, message: str): cipher = onetimepad.encrypt(message, 'a_random_key') gemb = discord.Embed(title='Encryption', 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{message}\n```') gemb.add_field(name='Output:', value=f'```\n{cipher}\n```', inline=False) await ctx.send(embed=gemb)
def add(name, name_of_note, content): # if there is no folder, create one if Notes.checkFolder(name) is False: os.system(f'cmd /c "cd notes & mkdir {name}"') file = open('./notes/{}/{}.txt'.format(name, name_of_note), 'a') password = udb.User.crypt_key(name) content = ot.encrypt(content, password) # encrypt contents of note file.write(content + '\n') file.close() udb.Logs.add_note(name, name_of_note) # update user logs print('Note made succesfully\n')
def encryptThing(self, thing, key): try: stringToReturn = onetimepad.encrypt(thing, key) self.cLog.log( "encrypting thing func runned successfully in main for password", "i") return str(stringToReturn) except Exception as e: print( "\nSomething went wrong while encrypting, Please Try again, if error persist, run troubleShoot command" ) input("press enter to continue...") self.cLog.log("error while encrypting thing in main for password", "e") self.cLog.exception(str(e), "mainForPassword.py/encryptThing")
def encryption(): if request.method == "POST": if "ceaserEncrypt" in request.form: req = request.form plaintext = req["ceaserPlainText"] cipher = [] for letter in plaintext: letter = ord(letter) letter = letter + 3 cipher.append(letter) encryptedText = [] for letters in cipher: letters = chr(letters) encryptedText.append(letters) answer = "".join(encryptedText) return render_template("/encryptIt.html", result=answer) elif "oneTimeEncrypt" in request.form: res = request.form plaintext = res["oneTimePadText"] import onetimepad cipher = onetimepad.encrypt(plaintext, 'random') return render_template("/encryptIt.html", results=cipher) elif "monoEncrypt" in request.form: req = request.form plaintext = req["monoText"] from string import printable from random import shuffle keys = list(printable) shuffle_keys = list(printable) shuffle(shuffle_keys) maps = dict(zip(keys, shuffle_keys)) reverse_map = dict(zip(shuffle_keys, keys)) cipher = [] for letters in plaintext: cipherletters = maps[letters] cipher.append(cipherletters) answer = "".join(cipher) return render_template("/encryptIt.html", resu=answer) return render_template("/encryptIt.html")
def update(name, name_of_note, content): #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 the 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), 'w') password = udb.User.crypt_key(name) content = ot.encrypt(content, password) #encrypt contents of updated note file.write(content+'\n') file.close() udb.Logs.update_note(name, name_of_note) #update user logs print('Note updated succesully\n')
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()
def encryptMessage(): pt = e1.get() # inbuilt function to encrypt a message ct = onetimepad.encrypt(pt, 'random') e2.insert(0, ct)
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 encrypt(self,m): return onetimepad.encrypt(m,self.__key.decode("ISO-8859-5"))
def EncryptONETIME(text, key): return onetimepad.encrypt(text,key)
def encrypted_text(username, password): cipher = onetimepad.encrypt(password, username) return cipher
From = input('Your email') password =input("your password") to = input("recipient") subject = input('enter your subject') body = input("enter your message") message = "Subject:{}\n\n{}".format(subject, body) key = '' cipher ='' Brovo = input('Do you want to chpher your message \n yes \n no \n') # this is asking if you want too cipher if Brovo == 'yes': key = input('please enter your key.') cipher = onetimepad.encrypt(message, key) Brovo = cipher elif Brovo == 'no': Brovo = message # This dictats the response. try: Alpha = smtplib.SMTP('smtp.gmail.com', 587) # Opening Alpha.starttls() #Secure TLS Alpha.login(From, password) #login Alpha.sendmail(From, to, Brovo) #Sending