Exemple #1
0
 def add_record(self):
     if self.master_pass is None:
         self.master_pass = self.get_master_password()
     username = input("username: "******"password: "******"website: ")
     description = input("description: ")
     key = input("key: ")
     record = {
         'username': username,
         'password': encrypt(self.master_pass, password),
         'website': website,
         'description': description,
         'key': key
     }
     self.data.append(record)
     self.save_data()
Exemple #2
0
def handle_message(event):
    # 変数
    user_id = event.source.user_id
    user_id_coded = encrypt(user_id, JSON_CRYPTO_PASSWORD, JSON_CRYPTO_IV)
    user_msg = event.message.text
    now = datetime.datetime.now()

    # json読み込み
    with open(LINKS_JSON, 'r', encoding='utf-8') as f:
        links = json.load(f)

    # jsonの中になかったらとりま
    if not(user_id_coded in links.keys()):
        links[user_id_coded] = {'no':0, 'state':'linking', 'param':0, 'symptoms':[], 'temperature':0}

    # ここで変数
    user_info = links[user_id_coded]

    # 生徒のstateで分岐
    # 出席番号危機だす
    if user_info['state'] == 'linking':
        # 番号
        user_no = list(map(lambda str: re.sub(r'\D', '', str), user_msg.split('-')))

        # 有効な入力
        if (len(user_no) == 3) and ((user_no[0]+user_no[1]+user_no[2]).isdecimal()) and (1 <= int(user_no[0]) <= 3) and (1 <= int(user_no[1]) <= 6) and (1 <= int(user_no[2]) <= 40):
            user_no = '{0}-{1}-{2}'.format(user_no[0], user_no[1], user_no[2])

            # かぶった時
            if user_no in links.values():
                msg = '既に登録されている出席番号です。別の出席番号を入力してください。'

            # 登録
            else:
                user_info['no'] = user_no
                user_info['state'] = 'linked'
                msg = '登録が完了しました。'

        else:
            msg = '出席番号を、次の(例)のように入力してください。\n(例):「1年C組27番」の場合\n 1-3-27 と入力\n(例):「2年E組9番」の場合\n 2-5-9と入力'

        # 変身!
        api.reply_message(event.reply_token, TextSendMessage(text=msg))

    # リンクしてるとき
    elif user_info['state'] == 'linked':
        if user_msg == '体調チェック':
            # 時刻によって分岐
            if (4 <= now.hour < 9) and (user_info['param'] == 0):
                msg = '朝の体調チェックを開始します。'
                user_info['symptoms'] = []
                user_info['param'] += 1

            else:
                msg = '体調チェックの時間外です。\n朝は4時から9時の間\n昼は12時から14時の間にお願いします。'

            # 変身!
            api.reply_message(event.reply_token, TextSendMessage(text=msg))

        # 朝のやつ
        if 1 <= user_info['param'] < 7:
            if re.fullmatch(r'はい|いいえ', user_msg):
                user_info['param'] += 1
                if re.fullmatch('はい', user_msg):
                    user_info['symptoms'].append(user_info['param'] - 1)

            else:
                error_msg = 'はい か いいえ で答えてください。'
                api.push_message(user_id, TextSendMessage(text=error_msg))


            msg = TextSendMessage(text=choice_questions[user_info['param']], quick_reply=QuickReply(items=choices))

            # 変人
            api.push_message(user_id, messages=msg)

        elif user_info['param'] == 7:
            # 前のやつの処理
            if re.fullmatch('はい', user_msg):
                user_info['symptoms'].append(user_info['param'])

            msg = tempr_question
            api.push_message(user_id, TextSendMessage(text=msg))

            user_info['param'] += 1

        elif user_info['param'] == 8:
            # 有効な入力か
            user_msg = re.sub(r'\D', '', user_msg)
            if not(user_msg == '') and (user_msg.isdecimal) and (300 <= int(user_msg) <= 450):
                user_info['temperature'] = round(float(int(user_msg) / 10), 1)

                msg = '朝の体調チェックが終了しました!お疲れさまでした。\n明日も忘れずにおねがいします\n\nこの体調チェックをやり直したい場合は、4時から9時までの間に、もう一度 体調チェックと入力してください。'
                user_info['param'] = 0

            else:
                msg = '無効な入力です。数値ではない、もしくはあり得ない体温です。\n\n' + tempr_question

            api.push_message(user_id, TextSendMessage(text=msg))

    # json保存
    links[user_id_coded] = user_info
    with open(LINKS_JSON, 'w', encoding='utf-8') as f:
        json.dump(links, f)

    # コマンドラインに出力
    if user_msg == os.environ['SECRET_WORD_BEE']:
        infos = [] # infoに複数形ありましぇええええんwww
        fmt = '| {0:>6} | {1:>18} | {2:>6} |'
        # 先に情報を取得
        for v in links.values():
            # info = [grade, class, num, no, symptoms, temperature]
            info = {'grade':v['no'][0], 'class':v['no'][2], 'num':v['no'][4:], 'no':v['no'], 'symptoms':v['symptoms'], 'temperature':v['temperature']}
            if not(info['symptoms'] == []) or (37.5 <= info['temperature']): infos.append(info)

        infos.sort(key=lambda x: (x['grade'], x['class'], x['num']))

        print('----------------------------------------------------------------')
        print(fmt.format('NO', 'SYMPTOMS', 'TEMP'))
        for info in infos: print(fmt.format(info['no'], ','.join(map(str, info['symptoms'])), str(info['temperature'])))
        print('----------------------------------------------------------------')

    elif user_msg == os.environ['SECRET_WORD_BUTTERFLY']:
        print(links)
Exemple #3
0
import encoder

# setting up the ciphertext
ciphertext = ''
keyphrase = 'CARDCIPHERCARDCIPHER'
plaintext = "JELLYLIKEABOVETHEHIGHWIRESIXQUAKINGPACHYDERMSKEPTTHECLIMAXOFTHEEXTRAVAGANZAINADAZZLINGSTATEOFFLUX"
plaintext *= 5200
deck = [i for i in xrange(1,53)]

c = card_chameleon.Cipher()
c.prepare_deck(deck)

for char in keyphrase:
    c.prng(deck, char, iv=True)

ct_list = encoder.encrypt(plaintext, c, deck, n=0)

for char in ct_list:
    ciphertext += char

# finding the index of coincidence
n = len(ciphertext)
freq = {}
alphabet = list('ABCDEFGHIJKLMNOPQRSTUVWXYZ')
freqsum = 0.0
last = -1
count = 0

for char in ciphertext:
    if not char in freq:
        freq[char] = 1
Exemple #4
0
        out = card
        if out == last:
            coincidences += 1
        last = out

    if coincidences:
        parser.error('The deck must contain all unique values of 1-52.')

if args.passphrase:
    passphrase = args.passphrase.upper().replace(' ','')
    for char in passphrase:
        alg.prng(deck, char, iv=True)

if args.encrypt:
    plaintext = args.encrypt.upper()
    encrypted = encoder.encrypt(plaintext, alg, deck, n=5)

    ciphertext = ''
    for index, char in enumerate(encrypted):
        if index % 5 < 4:
            ciphertext += char
        else:
            ciphertext += char + ' '
    print(ciphertext)

elif args.decrypt:
    ciphertext = args.decrypt.replace(' ','')
    decrypted = encoder.decrypt(ciphertext, alg, deck, n=5)

    plaintext = ''
    for char in decrypted:
if os.path.exists("./secure/password.codes"):
    passer = open("./secure/master.key", "r").read()
    ye = 1
    while ye:
        h = blake2b()
        entered_pass = getpass.getpass(
            prompt="please enter your main password: "******"utf-8")
        h.update(by)
        hasher = h.hexdigest()
        # passer = str(input("enter your main password to continue.."))
        if passer == hasher:
            ye = 0
            print(" generated code is \n")
            code = gen_password(f_type, code_len)
            cypher_code = (encoder.encrypt(bytes(code, "utf-8"), by))
            # cypher_code = cypher_code.decode("utf-8")
            with open("./secure/password.len", "a+") as len_file:
                len_file.write(str(len(cypher_code)) + "\n")
            with open("./secure/password.codes", "a+b") as code_file:
                code_file.write(cypher_code)
            print("\n " + code)
            print(
                "\n the cypher of code has been added to password.codes file, and won't be available without master password"
            )
        else:
            print("sorry wrong password, try again")
            continue

#this is to create the master.key and the password.codes file anew
else:
def dostuff(socket, config, num, start, end):
    comment, result= dorender(config, start=start,end=end)
    print (result)
    print('render result: %s' % comment)
    mysend(socket, (M_RESULT + "%d$$" + encoder.encrypt(result))%num)
    print("<Client: Done render.>")
Exemple #7
0
        if out == last:
            coincidences += 1
        last = out

    if coincidences:
        parser.error('The deck must contain all unique values of 1-52.')

if args.passphrase:
    passphrase = args.passphrase.upper()
    for char in passphrase:
        alg.mix_deck(deck)
        deck = alg.count_cut(deck, encoder.plist.index(char)+1)

if args.encrypt:
    plaintext = args.encrypt.upper()
    encrypted = encoder.encrypt(plaintext, alg, deck, 5, base)

    ciphertext = ''
    for index, char in enumerate(encrypted):
        if index % 5 < 4:
            ciphertext += char
        else:
            ciphertext += char + ' '
    print(ciphertext)

elif args.decrypt:
    ciphertext = args.decrypt.replace(' ','')
    decrypted = encoder.decrypt(ciphertext, alg, deck, 5, base)

    plaintext = ''
    for char in decrypted:
Exemple #8
0
def encrypt_message(event):
    global decrypted_message
    global output_file_name
    global encryption_key
    # Get the information from the entry boxes
    decrypted_message = message.get("1.0", END)
    output_file_name = output_file.get()
    encryption_key = alphabet_key.get()

    # Check to make sure a message was provided to encrypt
    if len(decrypted_message) < 1:
        messagebox.showinfo("Alert", "Please enter a message to encrypt.")
        return

    # Check to make sure an input file name was provided
    if len(input_file_name) < 1:
        messagebox.showinfo("Alert", "Please enter a file to use.")
        return

    # Check to make sure the input file name is valid
    input_name_ary = input_file_name.split(".")
    file_extension = input_name_ary[1]
    if file_extension != "png" and file_extension != "jpg":
        messagebox.showinfo(
            "Alert", "Please select a png or jpg image to encrypt with.")
        return

    # If an output file name was not provided, create one
    # Else, check the output name for the correct format
    if len(output_file_name) < 1:
        input_ary = input_file_name.split("/")
        file_name = input_ary[len(input_ary) - 1].split(".")
        output_file_name = file_name[0] + "_ENCRYPTED.png"
    else:
        output_ary = output_file_name.split(".")
        if len(output_ary) < 2:
            messagebox.showinfo(
                "Alert",
                "Please enter a valid file extension for the output file.")
            return
        if output_ary[1] != "png":
            messagebox.showinfo("Alert",
                                "The output format must be a .png file.")
            return

    # Check to make sure the encryption key is valid
    if len(encryption_key) < 1:
        encryption_key = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    else:
        if len(encryption_key) != 26:
            messagebox.showinfo(
                "Alert",
                "The encryption key should only contain 26 characters.")
            return
        for c in encryption_key:
            if not c.isalpha():
                messagebox.showinfo(
                    "Alert",
                    "The encryption key must contain only alpha characters.")
                return
        alphabet = set(string.ascii_lowercase)
        if not set(encryption_key.lower()) >= alphabet:
            messagebox.showinfo(
                "Alert",
                "The encryption key must contain all letters of the alphabet")
            return
        encryption_key = encryption_key.upper()

    # Call the encryption function and hold onto the results
    return_items = encoder.encrypt(decrypted_message, input_file_name,
                                   output_file_name, encryption_key)

    # Display the results of the encryption process
    messagebox.showinfo(
        "Alert",
        "Plaintext Message: " + return_items[0] + "\nAlphabet Key used: " +
        return_items[1] + "\nOutput File: " + return_items[2])