def __init__(self, user_id, user_pw, cert_pw): super().__init__() # 이 과정이 실행되기 위해선 관리자 권한이 필요할 수도 있다. self.setControl(self.prog_id) # 이 과정이 실행되기 위해선 관리자 권한이 필요하다. self._user_id = encrypt(ENCRYPTION_KEY, user_id) self._user_pw = encrypt(ENCRYPTION_KEY, user_pw) self._cert_pw = encrypt(ENCRYPTION_KEY, cert_pw) self.OnGetFidData.connect(self.process_event_fid_data) self.OnGetRealData.connect(self.process_event_real_data) self.fid = '2' self.tig_data = list() self.event_connect_loop = QEventLoop()
def main(): kirjainmerkit = {} morsemerkit = {} i, y = 0, 0 morsecodes = [ '.-', '-...', '-.-.', '-..', '.', '..-.', '--.', '....', '..', '.---', '-.-', '.-..', '--', '-.', '---', '.--.', '--.-', '.-.', '...', '-', '..-', '...-', '.--', '-..-', '-.--', '--..', '' ] kirjainmerkitmorset = string.ascii_lowercase kirjainmerkitmorset += ' ' kirjainmerkitmorset.split() kirjainmerkit = stringtomorse(kirjainmerkitmorset, morsecodes) morsemerkit = morsetostring(kirjainmerkitmorset, morsecodes) choice = int( input("Press 1 to encode a message, Press 2 to decrypt a message")) if choice == 1: name = input("Input the message you wish to encode: ") print("The encrypted message is: ") message = encrypt(name.lower(), kirjainmerkit) for i in message: print(i, end=' ') if choice == 2: name = input("Input the message you wish to decode: ") name.split() print("The decoded message is: ", end='') message = decode(name, morsemerkit) for i in message: print(i, end='')
def init(): tab = [ "-h", "--help", "-dir", "-er", "--encrypt", "-e", "decrypt", "-d", "--replace", "-r" ] if sys.argv[1] == "-h" or sys.argv[1] == "--help": functions.display_help() exit(0) if len(sys.argv) < 2: print("\033[1;31;40mBlad! Brak argumentow!") exit(1) if sys.argv[1] == "-dir": functions.find() exit(0) if (sys.argv[1] == "-c"): if len(sys.argv[1]) < 2: print("\033[1;31;40mZbyt mala ilosc argumentow!") exit(1) else: if (len(sys.argv) > 3): print("\033[1;31;40mBledne argumenty!") exit(1) else: functions.find_in_current_directory(sys.argv[2]) exit(0) if sys.argv[1] == "--encrypt" or sys.argv[1] == "-e" or sys.argv[ 1] == "-er": functions.encrypt(sys.argv[1], sys.argv[2]) exit(0) if sys.argv[1] == "--decrypt" or sys.argv[1] == "-d": functions.decrypt(sys.argv[2]) exit(0) if sys.argv[1] == "--replace" or sys.argv[1] == "-r": functions.replace(sys.argv[2], sys.argv[3], sys.argv[4]) exit(0) if sys.argv[1] == "-s": functions.file_statistics(sys.argv[2]) exit(0) if sys.argv[1] not in tab: print("\033[1;31;40mBledne argumenty!") exit(1)
def api_add_monitor(): payload = request.get_json(silent=True) json_data = validate_payload(payload) if json_data.get('error'): return jsonify(json_data), 400 if json_data.get('password'): json_data['password'] = encrypt(json_data['password']) json_data['created'] = datetime.utcnow() json_data['last_check'] = None json_data['ok'] = None data = add_data(json_data) return jsonify(data), data['status_code']
def api_edit_monitor(monitor_name): payload = request.get_json(silent=True) json_data = validate_payload(payload) if json_data.get('error'): return jsonify(json_data), 400 password = json_data.get('password') monitor_type = json_data.get('monitor_type') if monitor_type in ('basicAuth', 'tokenAuth') and password: # modify_data will skip all None values! password = encrypt(password) if password else None json_data['password'] = password data = modify_data(json_data) return jsonify(data), data['status_code']
def main(): kirjainmerkit = {} morsemerkit = {} i,y = 0,0 morsecodes = ['.-','-...','-.-.','-..','.','..-.','--.','....','..','.---','-.-','.-..','--','-.','---','.--.','--.-','.-.','...','-','..-','...-','.--','-..-','-.--','--..',''] kirjainmerkitmorset = string.ascii_lowercase kirjainmerkitmorset += ' ' kirjainmerkitmorset.split() kirjainmerkit = stringtomorse(kirjainmerkitmorset,morsecodes) morsemerkit = morsetostring(kirjainmerkitmorset,morsecodes) choice = int(input("Press 1 to encode a message, Press 2 to decrypt a message")) if choice == 1: name = input("Input the message you wish to encode: ") print("The encrypted message is: ") message = encrypt(name.lower(),kirjainmerkit) for i in message: print(i,end=' ') if choice == 2: name = input("Input the message you wish to decode: ") name.split() print("The decoded message is: ",end='') message = decode(name,morsemerkit) for i in message: print(i,end='')
import functions msg = input("Enter the msg") print(functions.encrypt(msg.upper())) dec = input("Enter the moarse code") print(functions.decrypt(dec))
''' File: set-user.py Author: Nathan Hoad Description: Used to set the password in the user's config file in a reasonably secure manner ''' import sys import os import configparser import functions if len(sys.argv) != 3: print("Usage: set-user.py [username] [password]") sys.exit(1) username = sys.argv[1] password = sys.argv[2] conf_file = os.path.join(os.environ['HOME'], '.makemerc') conf = configparser.RawConfigParser() # read in the config so we don't stomp out other values conf.read(conf_file) conf.set('settings', 'username', username) conf.set('settings', 'password', functions.encrypt(username, password)) with open(conf_file, 'w') as f: conf.write(f) print('Your username and password have now been securely set.')
Python 3.7.4 An encryption tool made in Python, based on ROT13 ''' import functions #User Interface/Inputs *Welcome Statements* userChoice = input("Would you like to Encrpyt or Decrypt a message (E or D): ") userChoice = userChoice.lower() #User Pick Encryption if userChoice == "e": userMessage = input("Enter the message you would like to encrypt: ") userMessage = userMessage.lower() userKey = input("Enter the key you would like to encrypt with: ") encryptedMessage = functions.encrypt(userMessage, userKey) print("Your encrypted message using the Key #{} is: ".format(userKey)) print(*encryptedMessage, sep='') #User Pick Decryption elif userChoice == "d": userMessage = input("Enter the message you would like to decrypt: ") userMessage = userMessage.lower() userKey = input("Enter the key you would like to decrypt with: ") decryptedMessage = functions.decrypt(userMessage, userKey) print("Your decrypted message using the Key #{} is: ".format(userKey)) print(*decryptedMessage, sep='') #Error else: print("Error! You did not enter the D or E key! Program Terminated :(")
import functions as rsa import requests # local test [[n, e], [d, p, q]] = rsa.generate_key_pair(512) # keys for A [[n1, e1], [d1, p1, q1]] = rsa.generate_key_pair(512) # keys for b while n1 < n: [[n1, e1], [d1, p1, q1]] = rsa.generate_key_pair(512) print(f"\nKeys of A\nn is: {hex(n)[2:]}\ne is: {hex(e)[2:]}\nfi(n) is: {hex(((p-1)*(q-1)))[2:]}\nd is: {hex(d)[2:]}\np is: {hex(p)[2:]}\nq is: {hex(q)[2:]}") print(f"\nKeys of B\nn1 is: {hex(n1)[2:]}\ne1 is: {hex(e1)[2:]}\nfi(n1) is: {hex(((p1-1)*(q1-1)))[2:]}\nd1 is:" f" {hex(d1)[2:]}\np is: {hex(p1)[2:]}\nq is: {hex(q1)[2:]}") # A encrypt msg and decrypt it msg = rsa.random.randint(2, 99999) C = rsa.encrypt(msg, e, n) decrypted_msg = rsa.decrypt(C, d, n) print("\n\n local test for encryption and decryption\n\nmsg is: " + str(msg) + "\nEncrypted msg is: " + str(C) + "\nDecrypted msg is: " + str(decrypted_msg)) print("\n\n--------------------------------------- local check for signing and verification --------------------------" "-------------\n\n") # A send signed msg to B msg = rsa.random.randint(2, 99999) print("msg is: " + str(msg)) signed_msg = rsa.send(msg, n1, e1, d, n) print("encrypted msg is:" + signed_msg[0] + "\nsignature is: " + signed_msg[1]) # B received signed_msg and knows e and n [check, k] = rsa.receive(signed_msg[0], signed_msg[1], n1, d1, e, n)
import functions as fn # задаём имена участникам names = 'AB' # генерируем закрытый, публичный ключи и число N для каждого пользователя из names keys = {} for i in names: keys[i] = fn.generatePublicAndSecretKeys() # вывод ключей всех пользователей for i in keys: print('key for', i, ' : ', keys[i]) print() # A шифрует сообщение для B. Для этого берёт открытый ключ и N пользователя B M = 'Hello' print('ENCRYPTION:\noriginal message :', M) # ключи d, e и число N пользователя B d, e, N = keys['B']['d'], keys['B']['e'], keys['B']['N'] # получение зашифрованного сообщения для пользователя B с помощью ключа e и числа N пользователя B encrypted, encryptedText = fn.encrypt(M, e, N) print('encrypted message for B :', encryptedText) # получение расшифрованного сообщения пользователем B с помощью ключа d и числа N decrypted, decryptedText = fn.decrypt(encrypted, d, N) print('\nDECRYPTION\nB`s decrypted message :', decryptedText)
def set_cert_pw(self, cert_pw): self._cert_pw = encrypt(ENCRYPTION_KEY, cert_pw)
def set_user_pw(self, user_pw): self._user_pw = encrypt(ENCRYPTION_KEY, user_pw)
def set_user_id(self, user_id): self._user_id = encrypt(ENCRYPTION_KEY, user_id)
<h2>Morse Code Translator</h2> <form action="" method="post"> <div class="form-input"> <label>Type your text</label> <input type="text" name="message" id="message"> </div> <div class="form-input"> <button id="translate" type="submit">Translate</button> </div> </form> </div> </div> </div> """) form = cgi.FieldStorage() message = form.getvalue("message") if message: message = str(message) result = encrypt(message.upper()) print(f""" <br> <div class="result"> <h4>Text entered: {message}</h4> <h4>Translation: {result}</h4> </div> """) print("""</body></html>""")