예제 #1
0
def chal1():
    """Convert a hex string to base64."""
    IN = '49276d206b696c6c696e6720796f757220627261696e206c696b6' \
         '5206120706f69736f6e6f7573206d757368726f6f6d'

    OUT = 'SSdtIGtpbGxpbmcgeW91ciBicmFpbiBsaWtlIGEgcG9pc29ub3VzIG11c2hyb29t'

    expect(utils.hex_to_base64(IN), OUT)
예제 #2
0
    def test_random_hex_number_returns_correct_base64_string(self):
        import string, random
        import codecs

        input_string = ''.join(
            random.choice('0123456789abcdef')
            for n in range(int(random.randint(1, 10000) * 2)))
        expected_output = codecs.encode(codecs.decode(input_string, 'hex'),
                                        'base64').decode().replace('\n', '')
        actual_output = hex_to_base64(input_string)

        self.assertEqual(expected_output, actual_output)
예제 #3
0
from utils import hex_to_base64
from utils import fixed_xor
from utils import single_byte_xor
from utils import find_message
from repkeyxor import encrypt

# 1-1. Hex to Base64

hex_input = '49276d206b696c6c696e6720796f757220627261696e206c696b65206120706f69736f6e6f7573206d757368726f6f6d'
b64_expected_result = 'SSdtIGtpbGxpbmcgeW91ciBicmFpbiBsaWtlIGEgcG9pc29ub3VzIG11c2hyb29t'

b64_result = hex_to_base64(hex_input)
assert b64_expected_result == b64_result
print('1-1. Hex to Base64: passed')

# 1-2. Fixed XOR

xor_input = 0x1c0111001f010100061a024b53535009181c
xor_key = 0x686974207468652062756c6c277320657965
xor_expected_result = 0x746865206b696420646f6e277420706c6179

xor_result = fixed_xor(xor_input, xor_key)
assert xor_expected_result == xor_result
print('1-2. Fixed XOR: passed')

# 1-3. Single byte XOR

hex_str = '1b37373331363f78151b7f2b783431333d78397828372d363c78373e783a393b3736'
sbx_expected_result = 'Cooking MC\'s like a pound of bacon'

sbx_result = single_byte_xor(hex_str)
예제 #4
0
__author__ = 'christianvriens'
__license__ = ''

import utils

# Challenge 1
the_string = '49276d206b696c6c696e6720796f757220627261696e206c696b65206120706f69736f6e6f7573206d757368726f6f6d'
should_produce = 'SSdtIGtpbGxpbmcgeW91ciBicmFpbiBsaWtlIGEgcG9pc29ub3VzIG11c2hyb29t'
result = utils.hex_to_base64(the_string)
print(utils.check_result(result, should_produce))
예제 #5
0
import argparse
import utils

# Convert hex to base64

# The string:

# 49276d206b696c6c696e6720796f757220627261696e206c696b65206120706f69736f6e6f7573206d757368726f6f6d

# Should produce:

# SSdtIGtpbGxpbmcgeW91ciBicmFpbiBsaWtlIGEgcG9pc29ub3VzIG11c2hyb29t

if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("input", help="Hexadecimal input for conversion")
    args = parser.parse_args()
    print("Input : ", args.input)
    print("Output : ", utils.hex_to_bytes(args.input).decode("utf-8"))
    print("Output : ", utils.hex_to_base64(args.input).decode("utf-8"))
예제 #6
0
 def test_singular_hex_character_returns_appropriate_base64_string(self):
     input_string = '3a'
     self.assertEqual('Og==', hex_to_base64(input_string))
예제 #7
0
 def test_empty_hex_input_returns_nothing(self):
     input_string = ''
     self.assertEqual('', hex_to_base64(input_string))
예제 #8
0
    def test_case_specified_in_docs(self):
        input_string = '49276d206b696c6c696e6720796f757220627261696e206c696b65206120706f69736f6e6f7573206d757368726f6f6d'
        expected_output = 'SSdtIGtpbGxpbmcgeW91ciBicmFpbiBsaWtlIGEgcG9pc29ub3VzIG11c2hyb29t'

        self.assertEqual(expected_output, hex_to_base64(input_string))
예제 #9
0
#!/usr/bin/env python

from utils import test, hex_to_base64

h2b64 = hex_to_base64('49276d206b696c6c696e6720796f757220627261696e206c696b'
                      '65206120706f69736f6e6f7573206d757368726f6f6d')

test(h2b64, 'SSdtIGtpbGxpbmcgeW91ciBicmFpbiBsaWtlIGEgcG9pc29ub3VzIG11c2hyb29t')