Beispiel #1
0
def create_message(filename):

    # Step 1: Read file and convert it to Base65536
    with open(filename, 'rb') as f:
        b65536 = base65536.encode(base64.b64encode(f.read())).replace('\n', '')

    # Step 2: Calculate maximum length of Base64 string
    rl = 10000 - (len(os.path.basename(filename)) + 31)

    # Step 3: Check length of Base64 string and split if necessary
    b65536s = [string for string in split(b65536, rl)]

    # Step 4: Create messages
    messages = []
    b65536sc = 0

    if len(b65536s) != 1:
      b65536sc = len(b65536s) - 1

    for msg in b65536s:
        messages.append('!!DMFS{{"fn":"{fn}","pt":{pt},"ct":"{ct}"}}'.format(fn=os.path.basename(filename), pt=b65536sc, ct=msg))  # json f***s up the unicoded chars making the message longer, I think
        b65536sc -= 1

    return messages
Beispiel #2
0
def test_hello_world():
    # https://github.com/ferno/base65536/blob/
    # 25d6ea5104a16c24787fa1d8b4af836ba8bb6214/test.js#L86
    encoded = base65536.encode(b'hello world')
    assert encoded == u'驨ꍬ啯𒁷ꍲᕤ'
    assert base65536.decode(encoded) == b'hello world'
Beispiel #3
0
def test_bad():
    # https://github.com/ferno/base65536/blob/
    # 25d6ea5104a16c24787fa1d8b4af836ba8bb6214/test.js#L24
    bad = base65536.encode(b'\x25') + base65536.encode(b'\x13')
    with pytest.raises(ValueError):
        base65536.decode(bad)
Beispiel #4
0
def assert_encoding(data):
    encoded = base65536.encode(data)
    for form in UNICODE_NORMAL_FORMS:
        assert unicodedata.normalize(form, encoded) == encoded
    assert base65536.decode(encoded) == data
Beispiel #5
0
def main():
    im = Image.open(str(input("Image Name: ")))
    start = time.time()
    i = True
    while i == True:
        try:
            uui = str(uuid.uuid4())
            os.mkdir(uui)
            i = False
        except:
            h = 0
            print("A")
    print(im.height+(im.width*im.height))
    im.save("gr.png")
    im = Image.open("gr.png")
    out = im
    out
    red = []
    blu = []
    gre = []
    for y in range(im.height):
        for x in range(im.width):
            red.append("{} ".format(base65536.encode(
                bytes(
                    str(
                        out.getpixel(
                            (x,y)
                            )
                            [0]
                            )
                            ,'utf-8'
                            ))))
            gre.append("{} ".format(base65536.encode(
                bytes(
                    str(
                        out.getpixel(
                            (x,y)
                            )
                            [1]
                            )
                            ,'utf-8'
                            ))))
            blu.append("{} ".format(base65536.encode(
                bytes(
                    str(
                        out.getpixel(
                            (x,y)
                            )
                            [2]
                            )
                            ,'utf-8'
                            ))))
        gre.append("\n ")
        blu.append("\n ")
        red.append("\n ")
    flr = open("{}\imgr.txt".format(uui),"w", encoding="utf-8")
    flg = open("{}\imgg.txt".format(uui),"w", encoding="utf-8")
    flb = open("{}\imgb.txt".format(uui),"w", encoding="utf-8")
    flr.write(str("".join(red)))
    flg.write(str("".join(gre)))
    flb.write(str("".join(blu)))
    out.show()
    print("Took {0:0.1f} seconds".format(time.time() - start))
    return uui
import base65536

hi = '''Base64 is used to encode arbitrary binary data as "plain" text using a small, extremely safe repertoire of 64 (well, 65) characters. Base64 remains highly suited to text systems where the range of characters available is very small -- i.e., anything still constrained to plain ASCII. Base64 encodes 6 bits, or 3/4 of an octet, per character.
However, now that Unicode rules the world, the range of characters which can be considered "safe" in this way is, in many situations, significantly wider. Base65536 applies the same basic principle to a carefully-chosen repertoire of 65,536 (well, 65,792) Unicode code points, encoding 16 bits, or 2 octets, per character. This allows up to 280 octets of binary data to fit in a Tweet.

Link to base65536: https://github.com/qntm/base65536
Anyways thanks for reading, here is the flag: GCTF{1f_17_l00k5_57up1d_bu7_17_w0rk5_17_41n7_57up1d}'''.encode(
)
f = open('output.bin', 'w')
f.write(base65536.encode(hi))
f.close()
Beispiel #7
0
def secure_encode_65536(input_data, secret):
    pickled = pickle.dumps(input_data)
    length = str(len(pickled)).encode('ascii')
    hmac_hash = hmac.new(secret, pickled, hashlib.sha256).digest()
    return base65536.encode(length + b'\0' + pickled + hmac_hash)
Beispiel #8
0
    def convert(self, inp, source, target, skip=False):
        if source == target:
            return inp
        if source == '65536':
            source = '0123456789'
            l = len(inp) if len(inp) > 3 else len(inp) + 1
            s = '>'
            s += 'Q' * (l // 4)
            s += 'L' if l % 4 == 3 else 'H' if l % 4 == 2 else 'B' if l % 4 == 1 else ''
            truct = base65536.decode(inp)
            total = 0
            count = 0
            for x in struct.unpack(s, truct):
                total += x * (2**64)**count
                count += 1
            inp = str(total)
        if type(source) == list:
            return "Cannot currently convert from time."
        if type(target) == list and not skip:
            b60str = self.convert(inp, source, target, skip=True)
            #             print(b60str)
            b60 = []
            for x in range(0, len(b60str) - 1, 2):
                b60.append(b60str[x:x + 2][::-1])
            minu = int(b60[-1])
            hour = 0
            counter = 0
            for x in b60[:-1][::-1]:
                hour += int(x) * 60**counter
                counter += 1
            hour = hour % 24
            return f'{hour}:{"0"*(2-len(str(minu)))}{minu}'

        if target == '65536':
            b10 = int(self.convert(inp, source, '0123456789'))
            nums = []
            s = '>'
            while b10 > 2**64 - 1:
                s += 'Q'
                nums.append(b10 % 2**64)
                b10 = b10 // (2**64)
            if b10 > 2**32 - 1:
                s += 'Q'
            elif b10 > 2**16 - 1:
                s += 'L'
            elif b10 > 2**8 - 1:
                s += 'H'
            else:
                s += 'B'
            nums.append(b10)

            return base65536.encode(struct.pack(s, *nums))
        sbase = len(source)
        tbase = len(target)
        inp = inp[::-1]
        num = 0
        startswith0 = False
        if inp[-1] == source[0]:
            startswith0 = True
        for x in range(0, len(inp)):
            num += source.index(inp[x]) * (sbase**x)
        string = ""
        while (True):
            string += str(target[num % tbase])
            num = num // tbase
            if num == 0: break
        if startswith0:
            string += (target[0])
        return string[::-1]
Beispiel #9
0
def test_ascii():
    encoded = base65536.encode(b'hello')
    assert encoded == u'\u9a68\ua36c\u156f'
    assert base65536.decode(encoded) == b'hello'
Beispiel #10
0
def test_non_ascii():
    # Python base65536-1.0 had a bug with UTF-8 encoded non-ASCII string.
    encoded = base65536.encode(u'안녕'.encode('utf-8'))
    assert base65536.decode(encoded).decode('utf-8') == u'안녕'
Beispiel #11
0
def test_hello_world():
    # https://github.com/ferno/base65536/blob/
    # 25d6ea5104a16c24787fa1d8b4af836ba8bb6214/test.js#L86
    encoded = base65536.encode(b'hello world')
    assert encoded == u'驨ꍬ啯𒁷ꍲᕤ'
    assert base65536.decode(encoded) == b'hello world'
Beispiel #12
0
def test_bad():
    # https://github.com/ferno/base65536/blob/
    # 25d6ea5104a16c24787fa1d8b4af836ba8bb6214/test.js#L24
    bad = base65536.encode(b'\x25') + base65536.encode(b'\x13')
    with pytest.raises(ValueError):
        base65536.decode(bad)
Beispiel #13
0
def assert_encoding(data):
    encoded = base65536.encode(data)
    for form in UNICODE_NORMAL_FORMS:
        assert unicodedata.normalize(form, encoded) == encoded
    assert base65536.decode(encoded) == data
Beispiel #14
0
def test_ascii():
    encoded = base65536.encode(b'hello')
    assert encoded == u'\u9a68\ua36c\u156f'
    assert base65536.decode(encoded) == b'hello'
Beispiel #15
0
def z85decode(x):
    return sum(Z85M[i] * (85**(len(x) - 1 - p)) for p, i in enumerate(x))


def z256decode(x):
    return sum(Z256M[i] * (256**(len(x) - 1 - p))
               for p, i in enumerate(x)) >> 8


if __name__ == "__main__":
    print(hex(256**8 - 1))
    # BASE56 12 CHARS WITH CS ON 5 BITS
    print(hex(((56**12) - 1) >> 5))
    print(hex(((56**12) - 1) >> 6))
    # BASE58 12 CHARS with CS ON 6 BITS
    print(hex(((58**12) - 1) >> 6))
    print(hex(((58**12) - 1) >> 7))
    # BASE85 10 CHARS WITHOUT CS
    print(hex((85**10 - 1) >> 0))
    print(hex((85**10 - 1) >> 1))

    for x in (0x00, 0x01, 0x456723AE62FEBC12, 0xFF6723AE62FEBCFE):
        assert x == z56decode(z56encode(x)) and z56check(z56encode(x))
        assert x == z58decode(z58encode(x)) and z58check(z58encode(x))
        assert x == z85decode(z85encode(x)) and True
        assert x == z256decode(z256encode(x)) and z58check(z58encode(x))
        print('%016x' % x, z56encode(x), z85encode(x), z256encode(x),
              base65536.encode(i2b(x, 8)))

    #print (''.join(chr(i) for i in range(33,1024)))
Beispiel #16
0
def test_non_ascii():
    # Python base65536-1.0 had a bug with UTF-8 encoded non-ASCII string.
    encoded = base65536.encode(u'안녕'.encode('utf-8'))
    assert base65536.decode(encoded).decode('utf-8') == u'안녕'
import base65536

hi = '''Base64 is used to encode arbitrary binary data as "plain" text using a small, extremely safe repertoire of 64 (well, 65) characters. Base64 remains highly suited to text systems where the range of characters available is very small -- i.e., anything still constrained to plain ASCII. Base64 encodes 6 bits, or 3/4 of an octet, per character.
However, now that Unicode rules the world, the range of characters which can be considered "safe" in this way is, in many situations, significantly wider. Base65536 applies the same basic principle to a carefully-chosen repertoire of 65,536 (well, 65,792) Unicode code points, encoding 16 bits, or 2 octets, per character. This allows up to 280 octets of binary data to fit in a Tweet.

Link to base65536: https://github.com/qntm/base65536
Anyways thanks for reading, here is the flag: GCTF{1f_17_l00k5_57up1d_bu7_17_w0rk5_17_41n7_57up1d}'''.encode()
f = open('output.bin','w')
f.write(base65536.encode(hi))
f.close()
def ByteToString(x):
    return base65536.encode(x)
Beispiel #19
0
import base65536

for b in range(0, 256):
    buf1 = bytearray([b])
    str1 = base65536.encode(buf1)
    buf2 = base65536.decode(str1)
    if buf1 != buf2:
        raise Exception

firstDefectStr = base65536.encode(bytearray([0, 110]))
firstDefectBuf = base65536.decode(firstDefectStr)
print(ord(firstDefectStr[0]) == 67072)
print(ord(firstDefectStr[0]) == 0x10600)
print(firstDefectBuf == bytearray([0, 110]))

for b1 in range(0, 256):
    for b2 in range(0, 256):
        buf1 = bytearray([b1, b2])
        str1 = base65536.encode(buf1)
        buf2 = base65536.decode(str1)
        if buf1 != buf2:
            raise Exception

buf = bytearray(b"hello world")
enc = base65536.encode(buf)
print(enc == "驨ꍬ啯𒁷ꍲᕤ")
dec = base65536.decode(enc)
print(dec == buf)

print("OK")