Example #1
0
def translate_instructions(lines_to_translate):
    binary_list = []
    lines = strip(lines_to_translate)
    for i in lines:
        if i[0] == '@':
            try:
                new_i = base2.encode(int(i[1:]))
                binary_list.append(new_i)
            except:
                pass
    return binary_list
Example #2
0
def a(message):
    conn,cur=sql()
    if message.content_type=="document":
        file_info = bot.get_file(message.document.file_id)
        downloaded_file = bot.download_file(file_info.file_path)
        with open(message.document.file_name, 'wb') as new_file:
            new_file.write(downloaded_file)
        markup=types.InlineKeyboardMarkup()
        markup.add(types.InlineKeyboardButton("Encrypt",callback_data="En_%s,%s"%(str(message.chat.id),message.document.file_name)),
                    types.InlineKeyboardButton("Decrypt",callback_data="De_%s,%s"%(str(message.chat.id),message.document.file_name)))
        bot.send_message(message.chat.id,"what do you want to do ?!",reply_to_message_id=message.message_id,reply_markup=markup)
    elif message.content_type=="photo":
        cur.execute("SELECT * FROM data where userid='%s';"%str(message.chat.id))
        r=cur.fetchall()
        if len(r)>0:
            userid=r[0][0]
            file_add=r[0][1]
            if r[0][3]=="dQ":
                try:    
                    bot.reply_to(message,"processing please wait ....")
                    file_info=bot.get_file(message.photo[-1].file_id)
                    downloaded_file = bot.download_file(file_info.file_path)
                    with open(str(message.chat.id)+'.jpg', 'wb') as new_file:
                        new_file.write(downloaded_file)
                    with open(str(message.chat.id)+'.jpg', 'rb') as image_file:
                        image = Image.open(image_file)
                        image.load()
                    codes = zbarlight.scan_codes('qrcode', image)
                    key2 = Fernet(codes[0])
                    f = MultiFernet([key2])
                    img = Image.open(file_add)
                    arr = np.array(img)
                    temp='';token=''
                    for row in arr:
                        for p in row:
                            if int(p[0])+int(p[1])+int(p[2]) <382:
                                temp+='0'
                            else:
                                temp+='1'
                            if len(temp)==8:
                                token+= chr(int(base2.decode(temp)))
                                temp=''
                    a=f.decrypt(str.encode(token))
                    w=open('de_'+file_add,'wb')
                    w.write(a)
                    w.close()
                    bot.send_photo(userid,open('de_'+file_add,'rb'))
                    os.remove(file_add)
                    os.remove(str(message.chat.id)+'.jpg')
                    os.remove('de_'+file_add)
                except Exception as e:
                    bot.reply_to(message,"QR-key is wrong...")
                    os.remove(file_add)
                    os.remove(str(message.chat.id)+'.jpg')
                
        else:
            bot.reply_to(message ,"?!!...")
    elif message.content_type=="text":
        cur.execute("SELECT * FROM data where userid='%s';"%str(message.chat.id))
        r=cur.fetchall()
        if len(r)>0:
            bot.reply_to(message,"processing please wait ....")
            userid=r[0][0]
            file_add=r[0][1]
            password = str.encode(message.text)
            salt = b'01s39*-/ q2@1z6!'
            kdf = PBKDF2HMAC(
                algorithm=hashes.SHA256(),
                length=32,
                salt=salt,
                iterations=100000,
                backend=default_backend())
            key = base64.urlsafe_b64encode(kdf.derive(password))
            f = MultiFernet([Fernet(key)])
            if r[0][3]=="de":                
                img = Image.open(file_add)
                arr = np.array(img)
                temp='';token=''
                for row in arr:
                    for p in row:
                        if int(p[0])+int(p[1])+int(p[2]) <382:
                            temp+='0'
                        else:
                            temp+='1'
                        if len(temp)==8:
                            token+= chr(int(base2.decode(temp)))
                            temp=''
                try:
                    a=f.decrypt(str.encode(token))
                    w=open('de_%s'%file_add,'wb')
                    w.write(a)
                    w.close()
                    bot.send_photo(userid,open('de_%s'%file_add,'rb'))
                    os.remove(file_add)
                    os.remove('de_'+file_add)
                except Exception as e:
                    bot.reply_to(message,"passkey is wrong...")
                    os.remove(file_add)
            elif r[0][3]=="en":
                w=open(file_add,'rb')
                b = f.encrypt(w.read())
                h=int(math.sqrt(len(b)*8)+1)
                data = np.zeros((h, h, 3), dtype=np.uint8)
                i=0;j=0
                for byte in b:
                    if len(base2.encode(byte))<8:
                        a="00000000"+base2.encode(byte)
                        a=a[len(a)-8:len(a)]
                        for bit in a:
                            if bit=='1':
                                data[j,i]=(255,255,255)
                            else:
                                data[j,i]=(bit,bit,bit)
                            if i+1<h:
                                i+=1
                            else:
                                i=0
                                j+=1
                img = Image.fromarray(data,"RGB")
                img.save('en_%s'%file_add)
                bot.send_document(userid,open('en_%s'%file_add,'rb'),caption="")
                os.remove(file_add)
                os.remove('en_%s'%file_add)
            cur.execute("DELETE FROM data WHERE userid='%s';"%str(userid))
            conn.commit()
        else:
            bot.reply_to(message ,"?!!...")
Example #3
0
            k_new += '010'
        if 'JGE' in k:
            k_new += '011'
        if 'JLT' in k:
            k_new += '100'
        if 'JNE' in k:
            k_new += '101'
        if 'JLE' in k:
            k_new += '110'
        if 'JMP' in k:
            k_new += '111'

    if k[0] == '@':
        k_new = k.replace('@', '')
        try:
            k_new = base2.encode(int(k_new))
        except:
            pass
        while len(k_new) < 16:
            k_new = '0' + k_new

    binary_list.append(k_new)

# 2. convert A-instructions
for k in final_lines_no_symbols.copy():
    if k[0] == '@':
        k_new = k.replace('@', '')
        try:
            k_new = base2.encode(int(k_new))
        except:
            pass
Example #4
0
def convert_to_binary(line):
    binary_code = base2.encode(int(line[1:]))
    return binary_code
Example #5
0
def convertTo15BitBinary(str):
    number = base2.encode(int(str))
    zeros = 16 - len(number)
    zero_str = zeros * "0"
    result = zero_str + number
    return (result)