def comm_login(self): """ 로그인 처리 함수. comm_init() 호출 후 통신 연결이 완료된 뒤에 호출 :return: 성공할 경우 True, 실패할 경우 False """ user_id = decrypt(ENCRYPTION_KEY, self.user_id) user_pw = decrypt(ENCRYPTION_KEY, self.user_pw) cert_pw = decrypt(ENCRYPTION_KEY, self.cert_pw) result = self.dynamicCall('CommLogin(user_id, user_pw, cert_pw)', user_id, user_pw, cert_pw) return True if result else False
def __main__(): ciphertext = 'BGRWSLNGJXXHTTQNRZAEWYPBHWALXDTLKOEJBRJPVUAGZXVKQDUUPNMMPGPPAQOWRHGKBOGGEOZKAPTUKTPLGUADVXXGWNFBHRIHPRPLTSUUHOKKZPENJGSWRVASVHEILVYQEQZHFUGHSIGZHLLONMNGRRXKCAAYBAKGDNSWFPUNVVGICTGNXSQNFEALZHPHCYVAAAGOQQDVLNTZYDILQSGUBRWGYICGCBXKCUITVBXWSGHSEEGGHEAAPAGOFIDPHAKVTZUXGZBIBTLLRNKQNTGVSQXLZSNZBSQVOITFUKXRHAPIAMPMWJVCTGNTXLVZAIZVECQQAXOFYBFOGZWISEHYZCUBTBRXEUPAPENRBIQUSINTATKHUVUEBTXALVOBRNOGMQIPVFVKEHOKUOUVYMMFUDPEGNXVLVZUEBXLSPGVVERRLIZKSTHNBXXRVHTKJOMLDPHTIRTKIFQYLIAMLEOQUMAEKGXVWMNIPOXRWEVTOAKEAHDLZFEUPRHFFWUFKXQWQIMIZVECLPNBHNZGSDNPMNPUNPGJHDEYKTVQGKPUZGGPDPNCATKLFBOVVIGUKMQIVCROXHEGEHATF' [m, freq] = functions.find_length(ciphertext) k = functions.find_key(ciphertext, freq, m) plaintext = functions.decrypt(ciphertext, k) #print(plaintext) toString(plaintext) return 0
def comm_logout(self): """ 로그아웃 함수. comm_terminate() 전에 호출한다. :return: 성공할 경우 True, 실패할 경우 False """ user_id = decrypt(ENCRYPTION_KEY, self.user_id) result = self.dynamicCall('CommLogout(user_id)', user_id) return True if result == 0 else False
def __init__(self, user_name=None): from config_secret import USER_INFO user_info = USER_INFO if user_name: user_info = USER_INFO[user_name] user_id = decrypt(ENCRYPTION_KEY, user_info['user_id']) user_pw = decrypt(ENCRYPTION_KEY, user_info['user_pw']) cert_pw = decrypt(ENCRYPTION_KEY, user_info['cert_pw']) super().__init__(user_id, user_pw, cert_pw) count = 1 while not self.login(): count += 1 if count > 100: break print(f'login 에 실패하여 재요청 중입니다 ({count} 번째 요청 중)')
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)
import functions msg = input("Enter the msg") print(functions.encrypt(msg.upper())) dec = input("Enter the moarse code") print(functions.decrypt(dec))
import functions msg = input("Enter the message") print(functions.encrypt(msg.upper())) moarse = input("Enter the moarse code") print(functions.decrypt(moarse))
#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 :(") exit()
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)
default_options['log_level'] = 'debug' default_options['log_format'] = '[%(asctime)s] %(levelname)s: %(message)s' default_options['date_format'] = '%Y-%m-%d %H:%M:%S' conf = configparser.RawConfigParser(default_options) conf.read(global_file) if not conf.read(user_file): print("No .makemerc file could be found. Check the documentation for details.", file=sys.stderr) print(conf.get('settings', 'imap_server')) sys.exit(1) # now let's get the config stuff that the user NEEDS to set. try: refresh_time = conf.get('settings', 'refresh_time') username = conf.get('settings', 'username') password = functions.decrypt(username, conf.get('settings', 'password')) patterns = conf.items('scripts') contact_address = conf.get('settings', 'contact_address') reconnect_attempts = conf.getint('settings', 'reconnect_attempts') except configparser.NoOptionError as e: print('{0}. Consult the documentation for help or add the missing option to your config file.'.format(e), file=sys.stderr) sys.exit(4) should_fork = conf.getboolean('settings', 'should_fork') first_email_sent = conf.getboolean('settings', 'first_email_sent') monitor_config = conf.getboolean('settings', 'monitor_config') unsent_save_location = conf.get('settings', 'unsent_save_location') log_file = conf.get('settings', 'log_file') log_level = conf.get('settings', 'log_level') log_format = conf.get('settings', 'log_format')