def Demoonizer(path, pss, pss2, salt, output): goodpss = pss.encode("utf-8") goodpss2 = pss2.encode("utf8") urfile = open(path, "rb+") tmp = urfile.read() for x in range(1, salt): goodpss = binascii.b2a_base64(goodpss) goodpss = base91.encode(goodpss) for x in range(1, salt): goodpss2 = binascii.b2a_base64(goodpss2) goodpss2 = base91.encode(goodpss2) verygoodpss = "" verygoodpss2 = "" for x in range(1, 33): verygoodpss += goodpss[int(int(len(goodpss) / 8) / int(x))] for x in range(1, 33): verygoodpss2 += goodpss2[int(int(len(goodpss2) / 8) / int(x))] cipher = AESCipher(verygoodpss2) cipher2 = AESCipher(verygoodpss) encrypted = cipher.decrypt(tmp) double_encrypted = cipher2.decrypt(encrypted) kek = str(double_encrypted) outfile = open(output, "wb") outfile.write(str(kek)) outfile.close() urfile.close() print "Done"
def run(s): mm = s.encode("utf8") output = "" output += "base16:" + base64.b16encode(mm).decode("utf8") try: output += "\r\nbase24:" + pybase24.encode24(mm) except: output += "\r\nbase24:失败" output += "\r\nbase32:" + base64.b32encode(mm).decode("utf8") try: output += "\r\nbase36:" + str(base36.loads(mm)) except: output += "\r\nbase36:失败" output += "\r\nbase58:" + base58.b58encode(mm).decode("utf8") output += "\r\nbase62:" + base62.encodebytes(mm) output += "\r\nbase64:" + base64.b64encode(mm).decode("utf8") output += "\r\nbase85:" + base64.b85encode(mm).decode("utf8") output += "\r\nbase91:" + base91.encode(mm) try: output += "\r\nbase92:" + base92.b92encode(mm).decode("utf8") except: output += "\r\nbase92:失败" try: output += "\r\nbase128:" + base128.encode(mm).decode("utf8") except: output += "\r\nbase128:失败" return output
def b91encode(src, table): if len(table) != 91: return 'Table length error' return base91.encode(src.encode()).translate(str.maketrans( b91table, table))
def save_to_files(out_data, dir_path, name): out_data_encoded = out_data.encode() with open(os.path.join(dir_path, name + ".dat"), "wb") as f: f.write(out_data_encoded) save_to_archives(out_data_encoded, dir_path, name + ".dat") base16_data = binascii.hexlify(out_data_encoded) with open(os.path.join(dir_path, name + ".base16"), "wb") as g: g.write(base16_data) # save_to_archives(base32_data, dir_path, name + ".base32") base32_data = base64.b32encode(out_data_encoded) with open(os.path.join(dir_path, name + ".base32"), "wb") as g: g.write(base32_data) # save_to_archives(base32_data, dir_path, name + ".base32") # base58_data = base58.b58encode(out_data_encoded) # with open(os.path.join(dir_path, name + ".base58"), "wb") as g: # g.write(base58_data) # save_to_archives(base58_data, dir_path, name + ".base58") base64_data = base64.b64encode(out_data_encoded) with open(os.path.join(dir_path, name + ".base64"), "wb") as g: g.write(base64_data) # save_to_archives(base64_data, dir_path, name + ".base64") base85_data = base64.b85encode(out_data_encoded) with open(os.path.join(dir_path, name + ".base85"), "wb") as g: g.write(base85_data) # save_to_archives(base85_data, dir_path, name + ".base85") ascii85_data = base64.a85encode(out_data_encoded) with open(os.path.join(dir_path, name + ".ascii85"), "wb") as g: g.write(ascii85_data) # save_to_archives(ascii85_data, dir_path, name + ".ascii85") res = out_data_encoded + b"=" * ((4 - len(out_data_encoded) & 3) & 3) z85_data = z85.encode(res) with open(os.path.join(dir_path, name + ".z85"), "wb") as g: g.write(z85_data) # save_to_archives(z85_data, dir_path, name + ".z85") base91_data = base91.encode(out_data_encoded).encode() with open(os.path.join(dir_path, name + ".base91"), "wb") as g: g.write(base91_data) # save_to_archives(base91_data, dir_path, name + ".base91") uu_data = codecs.encode(out_data_encoded, encoding="uu") with open(os.path.join(dir_path, name + ".uu"), "wb") as g: g.write(uu_data) # save_to_archives(uu_data, dir_path, name + ".uu") quopri_data = quopri.encodestring(out_data_encoded) with open(os.path.join(dir_path, name + ".quopri"), "wb") as g: g.write(quopri_data) # save_to_archives(quopri_data, dir_path, name + ".quopri") binhex.binhex(os.path.join(dir_path, name + ".dat"), os.path.join(dir_path, name + ".binhex"))
def prepare(self,filename): # 0 Sync Byte 1 0x55 # 1 Packet Type 1 0x66 Normal mode, 0x67 No-FEC mode. # 2 Callsign 4 Base-40 encoded. Up to 6 characters. # 6 Image ID 1 Incremented by 1 for each new image. # 7 Packet ID 2 The packet number within the image. # 9 Width 1 Width of the image in MCU blocks (pixels / 16). # 10 Height 1 Height of the image in MCU blocks (pixels / 16). # 11 Flags 1 [7:6] reserved, [5:3] JPEG quality, [2] EOI flag, [1:0] subsampling # 12 MCU Offset 1 Offset (bytes) to the beginning of the first MCU block in payload. # 13 MCU Index 2 The number of the MCU pointed to by the offset above. # 15 Payload 205 Payload data. # 220 Checksum 4 32-bit CRC. # 224 FEC 32 Reed-Solomon forward error correction data. rv = [] counter = 0 with open(filename, "rb") as f: # aprs = APRS(self.callsign, self.ssid) while True: frame = f.read(256) if len(frame) == 0: break # Sync byte, CRC and FEC of SSDV not transmitted # payload is 205 bytes, so I frame gets 103 bytes, J gets 102 bytes and a \0 header = frame [6: 15] dataI = frame[15:15+103] dataJ = frame[15+103:15+205] + b'\0' dataK = bytes([dataI[i] ^ dataJ[i] for i in range(len(dataI))]) pkt_base91 = encode(header+dataI) msg = self.create_ssdv_msg('I', counter, pkt_base91) counter += 1 rv.append(msg) pkt_base91 = encode(header+dataJ) msg = self.create_ssdv_msg('J', counter, pkt_base91) counter += 1 rv.append(msg) pkt_base91 = encode(header+dataK) msg = self.create_ssdv_msg('K', counter, pkt_base91) counter += 1 rv.append(msg) return rv
def encode(txt): print("[+]input is ", end="") print(txt) print( "==============================================================================" ) #base16 print("[成功]base16 encode: ", end="") print(base64.b16encode(txt)) #base32 print("[成功]base32 encode: ", end="") print(base64.b32encode(txt)) #base36 try: base36_m_str = bytes.decode(txt) base36_m_int = int(base36_m_str) base36_cipher = base36.dumps(base36_m_int) print("[成功]base36 encode: ", end="") print(base36_cipher) except Exception as e: print("[失败]base36 encode: ", end="") print("base36加密只支持整数数字") #base58 print("[成功]base58 encode: ", end="") print(base58.b58encode(txt)) #base62 print("[成功]base62 encode: ", end="") print(base62.encodebytes(txt)) #base64 print("[成功]base64 encode: ", end="") print(base64.b64encode(txt)) #base85 print("[成功]base85 encode: ", end="") print(base64.b85encode(txt)) #base91 print("[成功]base91 encode: ", end="") print(base91.encode(txt)) #base92 print("[成功]base92 encode: ", end="") print(py3base92.encode(txt))
async def on_message(message): if message.author == dbot.user: return if message.content.startswith('!start'): # To show who's game it is (no one else can play the game than this person) e = discord.Embed(title="%s's Game!" % message.author) # Generate Random Game Board start_array = np.zeros(shape=(4, 4)) first = randint(0, 3) second = randint(0, 3) start_array[first][second] = randint(1, 2) * 2 found = False while found is not True: first_2 = randint(0, 3) second_2 = randint(0, 3) if first_2 == first and second_2 == second: None else: found = True start_array[first_2][second_2] = randint(1, 2) * 2 #start_array[randint(0, 3)][randint(0, 3)] = randint(1, 90) * 2 string, string2 = array_to_string(start_array, message.author.mention) e.add_field(name="Try to get the 2048 tile!", value=string2) e.set_footer(text=base91.encode(bytes(string, 'utf-8'))) new_msg = await message.channel.send(embed=e) print(start_array) # Add control reactions for emoji in ['⬆', '⬇', '⬅', '➡']: await new_msg.add_reaction(emoji)
def base91encode(importx, infilepath, outfilepath, inputformat, raw, exportx): if importx == 'file': f = open(infilepath, 'r') raw = f.read() f.close() elif importx == 'print': raw = raw else: print('\033[1;31m[-]\033[0m Unknown error.') return False inp = raw if inputformat == 'base64': iput = base64.b64decode(inp) elif inputformat == 'raw': iput = inp elif inputformat == 'base32': iput = base64.b32decode(inp) elif inputformat == 'base16': iput = base64.b16decode(inp) elif inputformat == 'base58': iput = base58.b58decode(inp) elif inputformat == 'base85': print('\033[1;31m[-]\033[0m Option not available yet') elif inputformat == 'hex': iput = inp.decode('hex') elif inputformat == 'dec': print('\033[1;31m[-]\033[0m Option not available yet') elif inputformat == 'octal': print('\033[1;31m[-]\033[0m Option not available yet') elif inputformat == 'binary': iput = text_from_bits(inp) else: print('\033[1;31m[-]\033[0m Unknown error.') return False output = base91.encode(iput) if exportx == 'file': f = open(outfilepath, 'w') f.write(output) f.close() return True elif exportx == 'print': return output else: print('\033[1;31m[-]\033[0m Unknown error.') return False
def b91enc(data: typing.Union[str, bytes]) -> str: return base91.encode(_binary(data))
print(" ** Hospitable name must be at least one character long ** ") born1 = getpass.getpass(' Enter the name of the hospitable you were born in:') born2 = getpass.getpass(' Re-enter the name of the hospitable you were born in:') salt1 = hashlib.sha512(mname1).hexdigest() salt2 = hashlib.sha512(born1).hexdigest() salted = (salt1[0:64] + salt2[0:64]) pswd1 = getpass.getpass('Enter the wireless PW you wish to secure:') pswd2 = getpass.getpass('Re-enter the wireless PW you wish to secure:') while pswd1 != pswd2 or len(pswd1) < 8: if (pswd1 != pswd2): print(" ** Passwords did not match, try again!") if (len(pswd1) < 8): print(" ** Password must be at least 8 characters long!") pswd1 = getpass.getpass(' Enter the wireless PW you wish to secure:') pswd2 = getpass.getpass(' Re-enter the wireless PW you wish to secure:') hashed_pw = hashlib.sha512(salted+pswd1).hexdigest() base91_pw = base91.encode(hashed_pw) print("Your new password: " + base91_pw[0:63]) hashed_pw = None pswd1 = None pswd2 = None salt1 = None salt2 = None salted = None
async def on_reaction_add(reaction, user): # Stop the bot from going when it adds its own reactions if user == dbot.user: return # Just to show in the console which reaction is being sent print(reaction) # If the message that was reacted on was one sent by the bot, guaranteeing it's a game if reaction.message.author == dbot.user: # Game is over and anyone can delete the game board and reactions by reacting the X emoji if reaction.emoji == '🇽' and base91.decode( reaction.message.embeds[0].footer.text).decode( "utf-8") == "Game over!": await delete_game(reaction) else: # decode footer from base91 footer = base91.decode( reaction.message.embeds[0].footer.text).decode("utf-8") output, user2 = string_to_array(footer) # if the user is the same one that started the game if user2 == user.mention: original = output rows = output.shape[0] cols = output.shape[1] output2 = np.zeros(shape=(4, 4)) if reaction.emoji == '🇽': # Game is still going and original user can decide to delete game await delete_game(reaction) await reaction.message.remove_reaction(emoji=reaction, member=user) return # Rotate arrays to all be facing to the left to make actions on them easier elif reaction.emoji == '⬅': output = np.rot90(output, 0) elif reaction.emoji == '➡': output = np.rot90(output, 2) elif reaction.emoji == '⬆': output = np.rot90(output, 1) elif reaction.emoji == '⬇': output = np.rot90(output, 3) else: await reaction.message.remove_reaction(emoji=reaction, member=user) return # Move everything to the left 4 times to be sure to get everything for i in range(0, 3): output2 = np.zeros(shape=(4, 4)) for x in range(0, cols): for y in range(0, rows): if y != 0: if output[x][y - 1] == 0: output2[x][y - 1] = output[x][y] else: output2[x][y] = output[x][y] else: output2[x][y] = output[x][y] output = output2 # Combine adjacent equal tiles output3 = np.zeros(shape=(4, 4)) for x in range(0, cols): for y in range(0, rows): if y != 0: if output2[x][y - 1] == output2[x][y]: output3[x][y - 1] = output2[x][y] * 2 output2[x][y] = 0 else: output3[x][y] = output2[x][y] else: output3[x][y] = output2[x][y] output = output3 # Move over two more times and check if the board has a 2048 in it or if it's completely full found_win = False found_end = True for i in range(0, 1): output3 = np.zeros(shape=(4, 4)) for x in range(0, cols): for y in range(0, rows): if y != 0: if output[x][y - 1] == 0: output3[x][y - 1] = output[x][y] else: output3[x][y] = output[x][y] else: output3[x][y] = output[x][y] if output3[x][y] == 2048: found_win = True if output3[x][y] == 0: found_end = False output = output3 output2 = output3 e = discord.Embed(title="%s's Game!" % user) # Undo the rotations from before if reaction.emoji == '⬅': output2 = np.rot90(output2, 0) if reaction.emoji == '➡': output2 = np.rot90(output2, 2) if reaction.emoji == '⬆': output2 = np.rot90(output2, 3) if reaction.emoji == '⬇': output2 = np.rot90(output2, 1) # If there's a 2048 on the board, the player won! Add the win gif if found_win is True: e = discord.Embed() e.add_field(name="%s got the 2048 tile!" % user, value="You did it!!") e.set_image( url= "https://media1.giphy.com/media/l2SpR4slaePsGG49O/giphy.gif" ) e.set_footer(text=base91.encode(b"Game over!")) await reaction.message.edit(embed=e) for emoji in ['⬆', '⬇', '⬅', '➡']: await reaction.message.remove_reaction( emoji=emoji, member=dbot.user) await reaction.message.add_reaction('🇽') # If the array changed from how it was before and if there are any empty spaces on the board, add a random tile elif np.array_equal(output2, original) is False and found_end is False: if smoother == False: found = False while found is not True: first_2 = randint(0, 3) second_2 = randint(0, 3) if output2[first_2][second_2] == 0: found = True output2[first_2][second_2] = randint(1, 2) * 2 string, string2 = array_to_string(output2, user.mention) print(string) e.add_field(name="Try to get the 2048 tile!", value=string2) e.set_footer(text=base91.encode(bytes(string, 'utf-8'))) await reaction.message.edit(embed=e) # Check if there are valid moves and if not, end the game if check_valid(output2) is False: print("end") # If there are no 0's, check if there are any valid moves. If there aren't, say the game is over. e = discord.Embed() e.add_field( name="%s is unable to make any more moves." % user, value=":cry:") e.set_image( url= "https://media2.giphy.com/media/joNVQCtuecqHK/giphy.gif" ) e.set_footer(text=base91.encode(b"Game over!")) await reaction.message.edit(embed=e) for emoji in ['⬆', '⬇', '⬅', '➡']: await reaction.message.remove_reaction( emoji=emoji, member=dbot.user) await reaction.message.add_reaction('🇽') if smoother == True: found = False while found is not True: first_2 = randint(0, 3) second_2 = randint(0, 3) if output2[first_2][second_2] != 0: None else: found = True output2[first_2][second_2] = randint(1, 2) * 2 string, string2 = array_to_string( output2, user.mention) e = discord.Embed() e.add_field(name="Try to get the 2048 tile!", value=string2) e.set_footer( text=base91.encode(bytes(string, 'utf-8'))) await reaction.message.edit(embed=e) elif check_valid(output2) is False: print("end") # If there are no 0's, check if there are any valid moves. If there aren't, say the game is over. e = discord.Embed() e.add_field(name="%s is unable to make any more moves." % user, value=":cry:") e.set_image( url= "https://media2.giphy.com/media/joNVQCtuecqHK/giphy.gif" ) e.set_footer(text=base91.encode(b"Game over!")) await reaction.message.edit(embed=e) for emoji in ['⬆', '⬇', '⬅', '➡']: await reaction.message.remove_reaction( emoji=emoji, member=dbot.user) await reaction.message.add_reaction('🇽') else: print("else") # They made a valid move, but it didn't change anything, so don't add a new tile string, string2 = array_to_string(output2, user.mention) print(string) e.add_field(name="Try to get the 2048 tile!", value=string2) e.set_footer(text=base91.encode(bytes(string, 'utf-8'))) await reaction.message.edit(embed=e) # Remove reaction await reaction.message.remove_reaction(emoji=reaction, member=user)
def base_all(): cypher_text = '' plain_text = '' text = request.values.get('text') num_of_base = request.values.get('num_of_base') encode_or_decode = request.values.get('encode_or_decode') try: if text and num_of_base and encode_or_decode: if encode_or_decode == 'encode': plain_text = text.encode(encoding='utf-8') if num_of_base == '64': cypher_text = base64.b64encode(plain_text) elif num_of_base == '32': cypher_text = base64.b32encode(plain_text) elif num_of_base == '58': cypher_text = base58.b58encode(plain_text) elif num_of_base == '91': cypher_text = base91.encode(plain_text) # elif num_of_base == '92': # cypher_text = base92.encode(plain_text) elif num_of_base == '36': cypher_text = base36.loads(plain_text) # elif num_of_base=='16': # cypher_text = hex(plain_text) elif num_of_base == '62': cypher_text = base62.encodebytes(plain_text) elif num_of_base == '85': cypher_text = base64.a85encode(plain_text) if type(cypher_text) == bytes: resu = { 'code': 200, 'result': cypher_text.decode('utf-8'), 'length': len(cypher_text.decode('utf-8')) } else: resu = { 'code': 200, 'result': cypher_text, 'length': len(cypher_text) } return render_template('base-base64.html', result=resu) elif encode_or_decode == 'decode': cypher_text = text if num_of_base == '64': plain_text = base64.b64decode(cypher_text) elif num_of_base == '32': plain_text = base64.b32decode(cypher_text) elif num_of_base == '58': plain_text = base58.b58decode(cypher_text) elif num_of_base == '91': plain_text = base91.decode(cypher_text) # elif num_of_base == '92': # plain_text = base92.decode(cypher_text) elif num_of_base == '36': plain_text = base36.dumps(cypher_text) # elif num_of_base=='16': # plain_text = int(cypher_text) elif num_of_base == '62': plain_text = base62.decodebytes(cypher_text) elif num_of_base == '85': plain_text = base64.a85decode(cypher_text) if type(plain_text) == bytes: resu = { 'code': 200, 'result': plain_text.decode('utf-8'), 'length': len(plain_text.decode('utf-8')) } else: resu = { 'code': 200, 'result': plain_text, 'length': len(plain_text) } #resu = {'code': 200, 'cypher_text':plain_text.decode('utf-8') } return render_template('base-base64.html', result=resu) else: resu = {'code': 10001, 'message': 'args can not be blank!'} return render_template('base-base64.html', result=resu) except: resu = {'code': 10000, 'message': 'input error'} return render_template('base-base64.html', result=resu)
def BASE(): cypher_text = '' plain_text = '' #接收post的数据 data = request.get_data() data = data.decode('utf-8') data = json.loads(data) text = data['text'] #输入字符串 typed = data['typed'] #输入base(num),即base的类型 operator = data['operator'] #加密或者解密 # print(text) try: if text and typed and operator: if operator == 'encode': #加密算法 plain_text = text.encode(encoding='utf-8') if typed == 'BASE64': cypher_text = base64.b64encode(plain_text) elif typed == 'BASE32': cypher_text = base64.b32encode(plain_text) elif typed == 'BASE58': cypher_text = base58.b58encode(plain_text) elif typed == 'BASE91': cypher_text = base91.encode(plain_text) # elif num_of_base == '92': # cypher_text = base92.encode(plain_text) elif typed == 'BASE36': cypher_text = base36.loads(plain_text) # elif num_of_base=='16': # cypher_text = hex(plain_text) elif typed == 'BASE62': cypher_text = base62.encodebytes(plain_text) elif typed == 'BASE85': cypher_text = base64.a85encode(plain_text) if type(cypher_text) == bytes: resu = { 'code': 200, 'result': cypher_text.decode('utf-8'), 'length': len(cypher_text.decode('utf-8')) } #如果输出是字节流格式 else: resu = { 'code': 200, 'result': cypher_text, 'length': len(cypher_text) } #如果输出是字符串形式 return json.dumps(resu, ensure_ascii=False) elif operator == 'decode': #解密算法 cypher_text = text if typed == 'BASE64': plain_text = base64.b64decode(cypher_text) elif typed == 'BASE32': plain_text = base64.b32decode(cypher_text) elif typed == 'BASE58': plain_text = base58.b58decode(cypher_text) elif typed == 'BASE91': plain_text = base91.decode(cypher_text) # elif num_of_base == '92': # plain_text = base92.decode(cypher_text) elif typed == 'BASE36': plain_text = base36.dumps(cypher_text) # elif num_of_base=='16': # plain_text = int(cypher_text) elif typed == 'BASE62': plain_text = base62.decodebytes(cypher_text) elif typed == 'BASE85': plain_text = base64.a85decode(cypher_text) if type(plain_text) == bytes: resu = { 'code': 200, 'result': plain_text.decode('utf-8'), 'length': len(plain_text.decode('utf-8')) } # 如果输出是字节流格式 else: resu = { 'code': 200, 'result': plain_text, 'length': len(plain_text) } # 如果输出是字符串形式 #resu = {'code': 200, 'cypher_text':plain_text.decode('utf-8') } return json.dumps(resu, ensure_ascii=False) else: resu = {'code': 10001, 'result': '参数不能为空!'} return json.dumps(resu, ensure_ascii=False) except: resu = {'code': 10000, 'result': '输入字符集错误。'} return json.dumps(resu, ensure_ascii=False)
def main(): usage = "[*] Usage: %prog <-e|-d> <-c|--Caesar> <-m|--method Method> -t TEXT " parser = OptionParser(version="1.0.0", usage=usage) # base16 parser.add_option("-m", "--method", dest="method", action="store", metavar="METHOD", help="which method") parser.add_option("-e", "--encrypt", dest="deal", action="store_true", default="True", help="encrypt") parser.add_option("-d", "--decrypt", dest="deal", action="store_false", help="decrypt") parser.add_option("-t", "--text", dest="text", type="string", metavar="Text", help="input text") parser.add_option("-c", "--Caesar", dest="caesar", action="store_true", help="Caesar Cipher") (options, args) = parser.parse_args() if options.caesar == True: print("[*] Finish!!") print() for cnt in range(26): print("[*] " + caesar(options.text, cnt)) sys.exit() # encrypt if options.deal == True: if options.method in ["b16", "base16"]: print("[*] Finish!!") print() print("[*] " + base64.b16encode(options.text.encode('utf-8'))) sys.exit() elif options.method in ["b32", "base32"]: print("[*] Finish!!") print() print("[*] " + base64.b32encode(options.text.encode("utf-8"))) sys.exit() elif options.method in ["b64", "base64"]: print("[*] Finish!!") print() print("[*] " + base64.b64encode(options.text.encode("utf-8"))) sys.exit() elif options.method in ["b85a", "base85a"]: print("[*] Finish!!") print() print("[*] " + base64.a85encode(options.text.encode("utf-8"))) sys.exit() elif options.method in ["b85b", "base85b"]: print("[*] Finish!!") print() print("[*] " + base64.b85encode(options.text.encode("utf-8"))) sys.exit() elif options.method in ["b91", "base91"]: print("[*] Finish!!") print() print("[*] " + base91.encode(options.text.encode("utf-8"))) sys.exit() elif options.method in ["b92", "base92"]: print("[*] Finish!!") print() print("[*] " + base92.encode(options.text.encode("utf-8"))) sys.exit() elif options.method in ["b36", "base36"]: print("[*] Finish!!") print() print("[*] " + base36.loads(options.text)) sys.exit() elif options.method in ["b58", "base58"]: print("[*] Finish!!") print() print("[*] " + base58.b58encode(options.text)) sys.exit() elif options.method in ["b62", "base62"]: print("[*] Finish!!") print() print("[*] " + base62.encode(int(options.text))) sys.exit() else: if options.method in ["b16", "base16"]: print("[*] Finish!!") print() print("[*] " + base64.b16decode(options.text.encode("utf-8"))) sys.exit() elif options.method in ["b32", "base32"]: print("[*] Finish!!") print() print() print("[*] " + base64.b32decode(options.text.encode("utf-8"))) sys.exit() elif options.method in ["b64", "base64"]: print("[*] Finish!!") print() print("[*] " + base64.b64decode(options.text.encode("utf-8"))) sys.exit() elif options.method in ["b85a", "base85a"]: print("[*] Finish!!") print() print("[*] " + base64.a85decode(options.text.encode("utf-8"))) sys.exit() elif options.method in ["b85b", "base85b"]: print("[*] Finish!!") print() print("[*] " + base64.b85decode(options.text.encode("utf-8"))) sys.exit() elif options.method in ["b91", "base91"]: print("[*] Finish!!") print() print("[*] " + base91.decode(options.text)) sys.exit() elif options.method in ["b92", "base92"]: print("[*] Finish!!") print() print("[*] " + base92.decode(options.text.encode("utf-8"))) sys.exit() elif options.method in ["b36", "base36"]: print("[*] Finish!!") print() print("[*] " + base36.dumps(int(options.text))) sys.exit() elif options.method in ["b58", "base58"]: print("[*] Finish!!") print() print("[*] " + base58.b58decode(options.text)) sys.exit() elif options.method in ["b62", "base62"]: print("[*] Finish!!") print() print("[*] " + base62.decode(options.text)) sys.exit()
def __main__(): # insert into path sys.path.insert(0, os.getcwd()) # get argv if len(sys.argv) == 1: print("usage: zipdep file.py") sys.exit(1) filenames = sys.argv[1:] final_zipdep = sys.argv[1] # declare temporary dictionary loc = OrderedDict({"__name__": "__zipdep"}) # exec() file for filename in filenames: if not os.path.exists(filename): print("skipping file {} - does not exist".format(filename)) with open(filename) as f: try: exec(f.read(), {}, loc) except ImportError as e: print("seems like your modules weren't installed. error: {}".format(e)) raise # scan locals modules = {} if "__zipdep_zipmodules" in loc: print("found `zipdep_zipmodules, loading modules from here instead of scanning") # Just load a list of modules from here. for mod in loc["__zipdep_zipmodules"]: print("importing {}".format(mod)) md = importlib.import_module(mod) path = extract_path(md) if path: modules[mod] = (path, mod) else: for name, obj in loc.items(): if isinstance(obj, ModuleType): print("found module:", name) path = extract_path(obj) if path: if len(path) == 2: modules[path[1]] = path elif path: modules[name] = (path, name) # next, check if it has a __module__, for things such as sub-level functions (from x import y) if hasattr(obj, "__module__"): print("found object: {} with __module__: {}".format(name, obj.__module__)) if not obj.__module__: print("skipping object in local scope") continue # attempt to import if obj.__module__ in modules: print("module already imported; skipping") try: mod = importlib.import_module(obj.__module__) except ImportError: print("unable to import module: {}".format(obj.__module__)) else: print("found&imported module:", obj.__module__) path = extract_path(mod) if path: modules[name] = (path, name) print("constructing zipfile with modules: {}".format( ', '.join(["{} from {}".format(name, path[0]) for (name, path) in modules.items()]))) # create in-memory zip in_mem_zip = io.BytesIO() # create zipfile zf = zipfile.ZipFile(in_mem_zip, mode='w', compression=mode) # zip up modules for mod, path in modules.items(): print("zipping module", mod) zipdir(path[0], zf, path[1]) # close && seek zf.close() in_mem_zip.seek(0) # encode in base85 b85_data = encode(in_mem_zip.read()) if isinstance(b85_data, bytes): b85_str = b85_data.decode() else: b85_str = b85_data b85_str = b85_str.replace("\"", "\\\"") b85 = '\n'.join([b85_str[i:i+80] for i in range(0, len(b85_str), 80)]) # now the fun part templated = uppertemplate.format(zd_version=__version__, zd_zipfile=b85, zd_hasb91=__b95_available) in_mem_zip.close() # open file in r, read in contents, then re-open in 'w' to overwrite with open(final_zipdep) as f: contents = f.read() with open(final_zipdep + '.zipdep.py', 'w') as f: # Now save. f.write(templated + contents + lowertemplate) print("success! written to file {}".format(final_zipdep + ".zipdep.py"))
def B91(s,flg=1): if (flg !=0): return(base91.decode(s)) else: return(base91.encode(bytes(s.encode("utf-8"))))
def __main__(): # insert into path sys.path.insert(0, os.getcwd()) # get argv if len(sys.argv) == 1: print("usage: zipdep file.py") sys.exit(1) filenames = sys.argv[1:] final_zipdep = sys.argv[1] # declare temporary dictionary loc = OrderedDict({"__name__": "__zipdep"}) # exec() file for filename in filenames: if not os.path.exists(filename): print("skipping file {} - does not exist".format(filename)) with open(filename) as f: try: exec(f.read(), {}, loc) except ImportError as e: print("seems like your modules weren't installed. error: {}". format(e)) raise # scan locals modules = {} if "__zipdep_zipmodules" in loc: print( "found `zipdep_zipmodules, loading modules from here instead of scanning" ) # Just load a list of modules from here. for mod in loc["__zipdep_zipmodules"]: print("importing {}".format(mod)) md = importlib.import_module(mod) path = extract_path(md) if path: modules[mod] = (path, mod) else: for name, obj in loc.items(): if isinstance(obj, ModuleType): print("found module:", name) path = extract_path(obj) if path: if len(path) == 2: modules[path[1]] = path elif path: modules[name] = (path, name) # next, check if it has a __module__, for things such as sub-level functions (from x import y) if hasattr(obj, "__module__"): print("found object: {} with __module__: {}".format( name, obj.__module__)) if not obj.__module__: print("skipping object in local scope") continue # attempt to import if obj.__module__ in modules: print("module already imported; skipping") try: mod = importlib.import_module(obj.__module__) except ImportError: print("unable to import module: {}".format(obj.__module__)) else: print("found&imported module:", obj.__module__) path = extract_path(mod) if path: modules[name] = (path, name) print("constructing zipfile with modules: {}".format(', '.join([ "{} from {}".format(name, path[0]) for (name, path) in modules.items() ]))) # create in-memory zip in_mem_zip = io.BytesIO() # create zipfile zf = zipfile.ZipFile(in_mem_zip, mode='w', compression=mode) # zip up modules for mod, path in modules.items(): print("zipping module", mod) zipdir(path[0], zf, path[1]) # close && seek zf.close() in_mem_zip.seek(0) # encode in base85 b85_data = encode(in_mem_zip.read()) if isinstance(b85_data, bytes): b85_str = b85_data.decode() else: b85_str = b85_data b85_str = b85_str.replace("\"", "\\\"") b85 = '\n'.join([b85_str[i:i + 80] for i in range(0, len(b85_str), 80)]) # now the fun part templated = uppertemplate.format(zd_version=__version__, zd_zipfile=b85, zd_hasb91=__b95_available) in_mem_zip.close() # open file in r, read in contents, then re-open in 'w' to overwrite with open(final_zipdep) as f: contents = f.read() with open(final_zipdep + '.zipdep.py', 'w') as f: # Now save. f.write(templated + contents + lowertemplate) print("success! written to file {}".format(final_zipdep + ".zipdep.py"))
def base_all(): cypher_text = '' plain_text = '' text = request.values.get('text') #输入字符串 num_of_base = request.values.get('num_of_base') #输入base(num),即base的类型 encode_or_decode = request.values.get('encode_or_decode') #加密或者解密 try: if text and num_of_base and encode_or_decode: if encode_or_decode == 'encode': #加密算法 plain_text = text.encode(encoding='utf-8') if num_of_base == '64': cypher_text = base64.b64encode(plain_text) elif num_of_base == '32': cypher_text = base64.b32encode(plain_text) elif num_of_base == '58': cypher_text = base58.b58encode(plain_text) elif num_of_base == '91': cypher_text = base91.encode(plain_text) # elif num_of_base == '92': # cypher_text = base92.encode(plain_text) elif num_of_base == '36': cypher_text = base36.loads(plain_text) # elif num_of_base=='16': # cypher_text = hex(plain_text) elif num_of_base == '62': cypher_text = base62.encodebytes(plain_text) elif num_of_base == '85': cypher_text = base64.a85encode(plain_text) if type(cypher_text) == bytes: resu = { 'code': 200, 'result': cypher_text.decode('utf-8'), 'length': len(cypher_text.decode('utf-8')) } #如果输出是字节流格式 else: resu = { 'code': 200, 'result': cypher_text, 'length': len(cypher_text) } #如果输出是字符串形式 return json.dumps(resu, ensure_ascii=False) elif encode_or_decode == 'decode': #解密算法 cypher_text = text if num_of_base == '64': plain_text = base64.b64decode(cypher_text) elif num_of_base == '32': plain_text = base64.b32decode(cypher_text) elif num_of_base == '58': plain_text = base58.b58decode(cypher_text) elif num_of_base == '91': plain_text = base91.decode(cypher_text) # elif num_of_base == '92': # plain_text = base92.decode(cypher_text) elif num_of_base == '36': plain_text = base36.dumps(cypher_text) # elif num_of_base=='16': # plain_text = int(cypher_text) elif num_of_base == '62': plain_text = base62.decodebytes(cypher_text) elif num_of_base == '85': plain_text = base64.a85decode(cypher_text) if type(plain_text) == bytes: resu = { 'code': 200, 'result': plain_text.decode('utf-8'), 'length': len(plain_text.decode('utf-8')) } # 如果输出是字节流格式 else: resu = { 'code': 200, 'result': plain_text, 'length': len(plain_text) } # 如果输出是字符串形式 #resu = {'code': 200, 'cypher_text':plain_text.decode('utf-8') } return json.dumps(resu, ensure_ascii=False) else: resu = {'code': 10001, 'message': '参数不能为空!'} return json.dumps(resu, ensure_ascii=False) except: resu = {'code': 10000, 'message': '输入字符集错误。'} return json.dumps(resu, ensure_ascii=False)
born1 = getpass.getpass( ' Enter the name of the hospitable you were born in:') born2 = getpass.getpass( ' Re-enter the name of the hospitable you were born in:') salt1 = hashlib.sha512(mname1).hexdigest() salt2 = hashlib.sha512(born1).hexdigest() salted = (salt1[0:64] + salt2[0:64]) pswd1 = getpass.getpass('Enter the wireless PW you wish to secure:') pswd2 = getpass.getpass('Re-enter the wireless PW you wish to secure:') while pswd1 != pswd2 or len(pswd1) < 8: if (pswd1 != pswd2): print(" ** Passwords did not match, try again!") if (len(pswd1) < 8): print(" ** Password must be at least 8 characters long!") pswd1 = getpass.getpass(' Enter the wireless PW you wish to secure:') pswd2 = getpass.getpass(' Re-enter the wireless PW you wish to secure:') hashed_pw = hashlib.sha512(salted + pswd1).hexdigest() base91_pw = base91.encode(hashed_pw) print("Your new password: " + base91_pw[0:63]) hashed_pw = None pswd1 = None pswd2 = None salt1 = None salt2 = None salted = None