Beispiel #1
0
def decode(data, fn):
	secretKey = ()
	y = 0;
	temp;
	testResult = "";
	tempData = "";

	data = base64.base64decode( data );
	val = 0;

	for c in data:
		tempData += "{:02x}".format( c )

	data = urllib.parse.quote( tempData );
	secretKey = [ i for i in range( 256 ) ]

	for i in secretKey:
		y = ( y +  i + ord( fn[ i % len( fn ) ] ) ) % 256
		temp = i;
		secretKey[ x ] = secretKey[ y ];
		secretKey[ y ] = temp;

	x = 0;
	y = 0;
	var i = 0;
	
	for i in data:
		x = (x + 1) % 256;
		y = (y + secretKey[ x ] ) % 256;
		temp = secretKey[ x ];
		secretKey[ x ] = secretKey[ y ];
		secretKey[ y ] = temp;
		testResult = testResult + chr( ord( i ) ^ secretKey[ ( secretKey[ x ] + secretKey[ y ] ) % 256 ] );

	return testResult;
 def decode(self, value, encode_types):
     """根据encode_types对字符串进行解码"""
     for encode_type in encode_types:
         if encode_type == 'urlencode':
             value = urldecode(value)
         if encode_type == 'base64encode':
             value = str(base64decode(value.encode('utf-8')),
                         encoding='utf-8')
     return value
    def get_encode_types(self, value):
        value = str(value)
        encode_types = []
        if value == '':
            return encode_types
        """判断是否存在urlencode"""
        try:
            url_decode_value = urldecode(value)
        except:
            return False
        if url_decode_value != value:
            encode_types.append('urlencode')
        """判断是否为int或者float,避免后面的base64判断出错"""
        try:
            json_load_value = json.loads(url_decode_value)
            if isinstance(json_load_value, int) or isinstance(
                    json_load_value, float):
                return encode_types
        except:
            pass
        """调用base64decode,判断返回字符串是否在可见范围内"""
        try:
            base64decode_value = base64decode(url_decode_value.encode('utf-8'))
            string_basedecode = base64decode_value.decode()
            for _ in string_basedecode:
                if 32 <= ord(_) <= 126:
                    continue
                else:
                    return encode_types
        except:
            return encode_types
        """判断是否为base64加密"""
        try:
            if str(base64encode(base64decode_value),
                   encoding='utf-8') == url_decode_value:
                encode_types.append("base64encode")
        except:
            return encode_types

        return encode_types
Beispiel #4
0
    def _handle_data(self, topic, payload):
        # get location and device
        try:
            location = topic.split('/')[self.topic_index_location]
            device = topic.split('/')[self.topic_index_device]
        except (AttributeError, ValueError):
            self.logger.error("Topic '%s' not valid. Dropping." % topic)
            return

        # check payload
        try:
            readings = json_decode(
                base64decode(json_decode(payload)['m2m:cin']['con']))
        except (ValueError, KeyError, TypeError):
            self.logger.error('Damaged payload; discarding')
            return

        # push data
        for _, values in groupby(readings, key=lambda x: x['n']):
            sensor_cnt = self._get_target_container(location, device, 'number')
            for value in sorted(values, key=lambda x: x['t']):
                self.push_content(sensor_cnt, [value])
Beispiel #5
0
 def from_base64(self, content):
     text = base64.base64decode(content)
     return Readme(text=text)
Beispiel #6
0
 def testUUID4(self):
     """ WebSocket key should be a UUID4.
     """
     key = _create_sec_websocket_key()
     u = uuid.UUID(bytes=base64decode(key.encode("utf-8")))
     self.assertEqual(4, u.version)
Beispiel #7
0
# Variables
base_url = 'https://us-api.mimecast.com'
uri = '/api/managedsender/permit-or-block-sender'  #Example URI
url = base_url + uri
#Generate these keys in mimecast
access_key = 'String'
secret_key = 'String'
app_id = 'String'
app_key = 'String'

request_id = str(uuid.uuid4())
hdr_date = datetime.datetime.utcnow().strftime(
    '%a, %d %b %Y %H:%M:%S') + ' UTC'

data_to_sign = (hdr_date + ':' + request_id + ':' + uri + ':' + app_key)
b64d = base64.base64decode(secret_key)
hmac_sha1 = hmac.new(b64d, data_to_sign.encode(), digestmod=hashlib.sha1)
hmac_sha1 = hmac_sha1.digest()

signature = str(base64.b64encode(hmac_sha1))
signature = str(signature[2:1])

headers = {
    'Authorization': 'MC ' + access_key + ':' + signature,
    'x-mc-app-id': app_id,
    'x-mc-date': hdr_date,
    'x-mc-req-id': request_id,
    'Content-Type': 'application/json'
}

payload = {
def decryptAES(password, input_text):
    secret= rightAdjustForAES(password + admin_secret)
    cipher = AES.new(secret,AES.MODE_ECB)
    result = cipher.decrypt(base64decode(input_text.encode("utf-8"))).decode("utf-8")
    return result
Beispiel #9
0
def b64decode(s):
    return base64decode(str_to_bytes(s))
Beispiel #10
0
 def testUUID4(self):
     """ WebSocket key should be a UUID4.
     """
     key = _create_sec_websocket_key()
     u = uuid.UUID(bytes=base64decode(key.encode("utf-8")))
     self.assertEqual(4, u.version)
Beispiel #11
0
        parsed_line = json.loads(line)
    except Exception as e:
        print("\033[1;31;40m" + str(line[:-2]) + "\033[1;37;40m")
    if parsed_line["Type"] == "Debug Msg":
        try:
            msg = base64.b64decode(parsed_line["Message"]).decode('utf-8')
            print("\033[1;32;40m" + str(msg[:-2]) + "\033[1;37;40m")
        except Exception as e:
            pass
    elif parsed_line["Type"] == "Status":
        status = parsed_line["Status"]
        value = parsed_line["Value"]
        print("Status Msg: %s, %s" % (status, value))
    elif parsed_line["Type"] == "Settings":
        freq = parsed_line["Freq"]
        sf = parsed_line["SF"]
        bw = parsed_line["BW"]
        cr = parsed_line["CR"]
        mode = parsed_line["Mode"]
    elif parsed_line["Type"] == "Frame":
        frame["HDR Pkt Type"] = parsed_line["HDR Pkt Type"]
        frame["HDR Stream ID"] = parsed_line["HDR Stream ID"]
        frame["HDR TTL"] = parsed_line["HDR TTL"]
        frame["HDR Sender"] = parsed_line["HDR Sender"]
        frame["HDR Pre Offset"] = parsed_line["HDR Pre Offset"]
        frame["HDR Num Sym Offset"] = parsed_line["HDR Num Sym Offset"]
        frame["HDR Sym Offset"] = parsed_line["HDR Sym Offset"]
        frame["Header CRC"] = parsed_line["Header CRC"]
        frame["Data CRC"] = parsed_line["Data CRC"]
        frame["Data Payload"] = base64.base64decode(frame["Data Payload"])
Beispiel #12
0
import zlib
import base64
from Crypto.PublicKey import RSA
from Crypto.Cipher import PKCS1_OAEP

private_key = ""

rsakey = RSA.importKey(private_key)
rsakey = PKCS1_OAEP.new(rsakey)

chunk_size = 256
offset     = 0
decrypted  = ""
encrypted  = base64.base64decode(encrypted)

while offset < len(encrypted):
    descrypted += rsakey.decrypt(encrypted[offset: offset + chunk_size])
    offset += chunk_size

# now we decompress to original
plaintext = zlib.decompress(decrypted)

print plaintext
Beispiel #13
0
 def decrypt(self, enc):
     enc = base64.base64decode(enc)
     iv = enc[:16]
     cipher = AES.new(self.key, AES.MODE_CBC, iv)
     return unpad(cipher.decrypt(enc[16:]))
 def testNonce(self):
     """ WebSocket key should be a random 16-byte nonce.
     """
     key = _create_sec_websocket_key()
     nonce = base64decode(key.encode("utf-8"))
     self.assertEqual(16, len(nonce))
Beispiel #15
0
def line_counter(fileobj):
	txt = base64.base64decode(fileobj)
	eventLog = parseObject(txt)
	eventLog = json.dumps(eventLog)
	return eventLog
Beispiel #16
0
def b64decode(s):
    return base64decode(str_to_bytes(s))
Beispiel #17
0
 def from_base64(self, content):
     text = base64.base64decode(content)
     return Readme(text=text)
Beispiel #18
0
 def testNonce(self):
     """ WebSocket key should be a random 16-byte nonce.
     """
     key = _create_sec_websocket_key()
     nonce = base64decode(key.encode("utf-8"))
     self.assertEqual(16, len(nonce))
Beispiel #19
0
from base64 import decodestring as base64decode

loadfile = open("Output.txt", 'r')
readfile = loadfile.read()
# made by munsiwoo

tmp = base64decode(str(readfile).encode()).decode()
result = tmp

for x in range(36):
    tmp = base64decode(str(result).encode()).decode()
    result = tmp

print(result)