Transmission Terminated
3 months ago
Esprit curieux
import struct import platform is_x64 = platform.architecture()[0] == '64bit' if is_x64: SHIFT = 30 digit_size = struct.calcsize('I') else: SHIFT = 15 digit_size = struct.calcsize('H') def restore_python_long(): """ Restore python long integer value from memory """ # hard coded data bytes from memory if is_x64: ob_size_data_str = '05 00 00 00 00 00 00 00' ob_digit_data_str = '11 11 00 00 fc ff bb 3b de dd cd 0c f3 ee ae 2a aa 00 00 00' else: ob_size_data_str = '09 00 00 00' ob_digit_data_str = '11 11 00 00 fc 7f 77 77 de 5d 9b 19 f3 6e 5d 55 aa 00' ob_size_data = ob_size_data_str.replace(' ', '').decode('hex') ob_digit_data = ob_digit_data_str.replace(' ', '').decode('hex') # get ob_size if is_x64: ob_size = struct.unpack('q', ob_size_data)[0] else: ob_size = struct.unpack('i', ob_size_data)[0] if ob_size == 0: return 0L # get digits digits = [] for i in xrange(0, abs(ob_size)): digit_value = ob_digit_data[i * digit_size: i * digit_size + digit_size] if is_x64: digits.append(struct.unpack('I', digit_value)[0]) else: digits.append(struct.unpack('H', digit_value)[0]) # restore long value = 0L for i in xrange(0, abs(ob_size)): value += digits[i] * 2 ** (SHIFT * i) if ob_size < 0: value = -value return value value = restore_python_long() print hex(value) print valueAnd the result is the same as input:
from PIL import Image, ImageChops image1 = Image.open('pic1.jpg') image2 = Image.open('pic2.jpg') diff = ImageChops.difference(image1, image2) diff.save('diff.jpg')
import java.io.PrintStream; import java.math.BigInteger; public class guess { public guess() { } static String XOR(String _str_one, String _str_two) { BigInteger i1 = new BigInteger(_str_one, 16); BigInteger i2 = new BigInteger(_str_two, 16); BigInteger res = i1.xor(i2); String result = res.toString(16); return result; } public static void main(String args[]) { int guess_number = 0; int my_num = 0x14d8f707; int my_number = 0x5c214f6c; int flag = 0x149b861a; if(args.length > 0) { try { guess_number = Integer.parseInt(args[0]); if(my_number / 5 == guess_number) { String str_one = "4b64ca12ace755516c178f72d05d7061"; String str_two = "ecd44646cfe5994ebeb35bf922e25dba"; my_num += flag; String answer = XOR(str_one, str_two); System.out.println((new StringBuilder("your flag is: ")).append(answer).toString()); } else { System.err.println("wrong guess!"); System.exit(1); } } catch(NumberFormatException e) { System.err.println("please enter an integer \nexample: java -jar guess 12"); System.exit(1); } } else { System.err.println("wrong guess!"); int num = 0xf4240; num++; System.exit(1); } } }
print '%x' % (0x4b64ca12ace755516c178f72d05d7061 ^ 0xecd44646cfe5994ebeb35bf922e25dba)
print ''.join(map(chr, [0x20, 0x64, 0x65, 0x36, 0x38, 0x33, 0x38, 0x32, 0x35, 0x32, 0x66, 0x39, 0x35, 0x64, 0x33, 0x62, 0x39, 0x65, 0x38, 0x30, 0x33, 0x62, 0x32, 0x38, 0x64, 0x66, 0x33, 0x33, 0x62, 0x34, 0x62, 0x61, 0x61, 0x00]))
# read data data = [] with open('hidden-message.pcap', 'rb') as f: data = f.read() # get bits bits = '' for i in xrange(75, len(data), 81): bits += '0' if data[i:i+1]=='I' else '1' # convert to chars flag = '' for i in xrange(0, len(bits), 8): flag += chr(int(bits[i:i+8], 2)) print flag
from PIL import Image # solved sudoku s = ''' 964127538 712385694 385496712 491578263 238614975 576239841 627843159 153962487 849751326 ''' s = s.replace('\n', '') image = Image.open('image.png').convert('RGB') out_image = Image.new('RGB', image.size) for j in xrange(0, 9): for i in xrange(0, 9): img_cell = image.crop((i * 50, j * 50, i * 50 + 50, j * 50 + 50)) # get pos (column) column = (int(s[j * 9 + i]) - 1) * 50 out_image.paste(img_cell, (column, j * 50)) out_image.save('out_image.png')
class A(object): """Class A""" def foo(self): """Function foo""" pass A.__doc__ = 'A class'
static PyGetSetDef type_getsets[] = { ... {"__doc__", (getter)type_get_doc, NULL, NULL}, ... }
a = A() a.__doc__ = 'A' print a.__doc__ A print A.__doc__ Class A
class A(object): """Class A""" def foo(self): """Function foo""" print 'A.foo()' def update_class_doc(cls, new_doc): new_dict = dict(cls.__dict__) new_dict['__doc__'] = new_doc new_cls = type(cls.__name__, A.__bases__, new_dict) return new_cls A = update_class_doc(A, 'Updated docstring of class A')
print A.__doc__
Updated docstring of class A
A.foo.__doc__ = 'Updated docstring of foo'
static PyGetSetDef instancemethod_getset[] = { {"__doc__", (getter)instancemethod_get_doc, NULL, NULL}, {0} };
print A.foo.__doc__ Function foo A.foo.__func__.__doc__ = 'Updated docstring of foo' print A.foo.__doc__ Updated docstring of foo
A.foo.im_func.__doc__ = 'Updated docstring of foo 2' print A.foo.__doc__ Updated docstring of foo 2
static PyGetSetDef type_getsets[] = { ... {"__doc__", (getter)type_get_doc, (setter)type_set_doc, NULL}, ... }
A.__doc__ = 'A class'
#!/usr/bin/evn python | |
# -*- coding: utf-8 -*- | |
import sys | |
import math | |
import struct | |
if sys.version_info > (3, 0): | |
basestring_type = str | |
else: | |
basestring_type = basestring | |
HASH_BITS = 61 if struct.calcsize('P') >= 8 else 31 | |
HASH_MODULUS = 2 ** HASH_BITS - 1 | |
PyLong_SHIFT = 30 | |
PyLong_BASE = 1 << PyLong_SHIFT | |
PyLong_MASK = PyLong_BASE - 1 | |
def toint32(x): | |
return int((x & 0xffffffff) - ((x & 0x80000000) << 1)) | |
def toint64(x): | |
return int((x & 0xffffffffffffffff) - ((x & 0x8000000000000000) << 1)) | |
def handle_overflow(value): | |
""" simulate integer overflow """ | |
if struct.calcsize('P') * 8 == 64: | |
return toint64(value) | |
return toint32(value) | |
def string_hash(str_value): | |
if not str_value: | |
return 0 | |
c = str_value[0] | |
res = ord(c) << 7 | |
for c in str_value: | |
res = (1000003 * res) ^ ord(c) | |
res ^= len(str_value) | |
res = handle_overflow(res) | |
if res == -1: | |
res = -2 | |
return res | |
def string_hash_py34(str_value): | |
if not str_value: | |
return 0 | |
raise Exception('Unknown SipHash random seed!') | |
def int_hash(int_value): | |
res = handle_overflow(int_value % (2 ** (struct.calcsize('l') * 8) - 1)) | |
if int_value < 0: | |
res = handle_overflow(int_value % (2 ** (struct.calcsize('l') * 8) - 1) + 1) | |
if res == -1: | |
res = -2 | |
return res | |
def get_pylong_from_long(value): | |
""" | |
Get a python long object. Returns a tuple with object size and digits. | |
Object size is based on a sign of value and digits number. | |
""" | |
negative = value < 0 | |
abs_value = abs(value) | |
# count the number of digits | |
digits = [] | |
t = abs_value | |
while t: | |
digits.append(t & PyLong_MASK) | |
t >>= PyLong_SHIFT | |
long_object_size = -len(digits) if negative else len(digits) | |
return long_object_size, digits | |
def int_hash_py3(int_value): | |
digits_num, digits = get_pylong_from_long(int_value) | |
if digits_num == -1: | |
return -2 if digits[0] == 1 else -digits[0] | |
elif digits_num == 0: | |
return 0 | |
elif digits_num == 1: | |
return digits[0] | |
sign = 1 if int_value > 0 else -1 | |
# compute a hash | |
x = 0 | |
for d in digits[::-1]: | |
x = ((x << PyLong_SHIFT) & HASH_MODULUS) | (x >> (HASH_BITS - PyLong_SHIFT)) | |
x += d | |
if x >= HASH_MODULUS: | |
x -= HASH_MODULUS | |
x *= sign # apply sign | |
x = handle_overflow(x) | |
if x == -1: | |
x = -2 | |
return x | |
def float_hash_py3(float_value): | |
if math.isnan(float_value) or math.isinf(float_value): | |
if math.isinf(float_value): | |
return -314159 if float_value < 0 else 314159 | |
else: | |
return 0 | |
m, e = math.frexp(float_value) | |
sign = 1 | |
if m < 0: | |
sign = -1 | |
m = -m | |
x = 0 | |
while m: | |
x = ((x << 28) & HASH_MODULUS) | x >> (HASH_BITS - 28) | |
m *= 268435456.0 # 2**28 | |
e -= 28 | |
y = int(m) # pull out integer part | |
m -= y | |
x += y | |
if x >= HASH_MODULUS: | |
x -= HASH_MODULUS | |
# adjust for the exponent; first reduce it modulo HASH_BITS | |
e = e % HASH_BITS if e >= 0 else HASH_BITS - 1 - ((-1 - e) % HASH_BITS) | |
x = ((int(x) << e) & HASH_MODULUS) | int(x) >> (HASH_BITS - e) | |
x *= sign | |
x = handle_overflow(x) | |
if x == -1: | |
x = -2 | |
return x | |
def float_hash(float_value): | |
if math.isnan(float_value) or math.isinf(float_value): | |
if math.isinf(float_value): | |
return -271828 if float_value < 0 else 314159 | |
else: | |
return 0 | |
fractpart, intpart = math.modf(float_value) | |
if fractpart == 0.0: | |
# this must return the same hash as an equal int or long | |
return int_hash(int(float_value)) # use int hash | |
fractpart, expo = math.frexp(float_value) | |
val = fractpart * 2147483648.0 # 2**31 | |
hipart = int(val) | |
val = (val - float(hipart)) * 2147483648.0 # get the next 32 bits | |
res = hipart + int(val) + (expo << 15) | |
res = handle_overflow(res) | |
if res == -1: | |
res = -2 | |
return res | |
def complex_hash(complex_value): | |
hashreal = float_hash(complex_value.real) | |
if hashreal == -1: | |
return -1 | |
hashimag = float_hash(complex_value.imag) | |
if hashimag == -1: | |
return -1 | |
res = hashreal + 1000003 * hashimag | |
res = handle_overflow(res) | |
if res == -1: | |
res = -2 | |
return res | |
# bool hash is based on int hash | |
bool_hash = int_hash | |
def object_hash(object_value): | |
res = id(object_value) | |
sizeof_void_p = struct.calcsize('P') | |
res = handle_overflow((res >> 4) | (res << (8 * sizeof_void_p - 4))) | |
if res == -1: | |
res = -2 | |
return res | |
def tuple_hash(tuple_value): | |
mult = 1000003 | |
res = 0x345678 | |
tuple_len = len(tuple_value) | |
for item in tuple_value: | |
tuple_len -= 1 | |
if isinstance(item, basestring_type): | |
item_hash = string_hash(item) | |
elif isinstance(item, bool): | |
item_hash = bool_hash(item) | |
elif isinstance(item, int): | |
item_hash = int_hash(item) | |
elif isinstance(item, float): | |
item_hash = float_hash(item) | |
elif isinstance(item, complex): | |
item_hash = complex_hash(item) | |
elif isinstance(item, tuple): | |
item_hash = tuple_hash(item) | |
elif isinstance(item, frozenset): | |
item_hash = frozenset_hash(item) | |
elif isinstance(item, object): | |
item_hash = object_hash(item) | |
else: | |
raise TypeError('unhashable type: %s' % str(type(item))[6:-1]) | |
if item_hash == -1: | |
return -1 | |
res = (res ^ item_hash) * mult | |
mult += int(82520 + tuple_len * 2) | |
res += 97531 | |
res = handle_overflow(res) | |
if res == -1: | |
res = -2 | |
return res | |
def frozenset_hash(frozenset_value): | |
h = 1927868237 | |
h *= len(frozenset_value) + 1 | |
for item in frozenset_value: | |
if isinstance(item, basestring_type): | |
item_hash = string_hash(item) | |
elif isinstance(item, bool): | |
item_hash = bool_hash(item) | |
elif isinstance(item, int): | |
item_hash = int_hash(item) | |
elif isinstance(item, float): | |
item_hash = float_hash(item) | |
elif isinstance(item, complex): | |
item_hash = complex_hash(item) | |
elif isinstance(item, tuple): | |
item_hash = tuple_hash(item) | |
elif isinstance(item, frozenset): | |
item_hash = frozenset_hash(item) | |
elif isinstance(item, object): | |
item_hash = object_hash(item) | |
else: | |
raise TypeError('unhashable type: %s' % str(type(item))[6:-1]) | |
h ^= (item_hash ^ (item_hash << 16) ^ 89869747) * 3644798167 | |
h = h * 69069 + 907133923 | |
if h == -1: | |
h = 590923713 | |
res = handle_overflow(h) | |
return res | |
# update some functions for python 3 | |
if sys.version_info > (3, 0): | |
int_hash = int_hash_py3 | |
float_hash = float_hash_py3 | |
if sys.version_info >= (3, 4): | |
string_hash = string_hash_py34 | |
def main(): | |
print('====================================================') | |
print('Testing Python hash algorithms') | |
print('====================================================') | |
print('hash(integer):') | |
i = -1234567890123456798 | |
print(hash(i)) | |
print(int_hash(i)) | |
print('---------------') | |
print('hash(float):') | |
f = 123456789.01234 | |
print(hash(f)) | |
print(float_hash(f)) | |
print('---------------') | |
print('hash(complex):') | |
c = 1 + 2.34j | |
print(hash(c)) | |
print(complex_hash(c)) | |
print('---------------') | |
print('hash(boolean):') | |
b = True | |
print(hash(b)) | |
print(bool_hash(b)) | |
print('---------------') | |
print('hash(None):') | |
n = None # object, type | |
print(hash(n)) | |
print(object_hash(n)) | |
print('---------------') | |
print('hash(object):') | |
class A(object): pass | |
print(hash(A)) | |
print(object_hash(A)) | |
if sys.version_info < (3, 4): | |
print('---------------') | |
print('hash(string):') | |
s = 'Hello world!!!' | |
print(hash(s)) | |
print(string_hash(s)) | |
print('---------------') | |
print('hash(tuple)') | |
t = (False, '1', 2, (4.5, 6 - 7.8j, (('deeper',), 'inner')), None, object, type, frozenset([1, 2, 3])) | |
print(hash(t)) | |
print(tuple_hash(t)) | |
print('---------------') | |
print('hash(frozenset)') | |
fs = frozenset([30, True, None, '123', 2.3, frozenset({1, '2', frozenset({1, '2', 3})})]) | |
print(hash(fs)) | |
print(frozenset_hash(fs)) | |
print('====================================================') | |
if __name__ == '__main__': | |
main() |
import struct data = 'Oqiqb4EhM/4jISMjlzQf6kpGQwLrG+GEIY4bPc0JL/jWBfNLejmbme3garIrG4ngbXtWQY3Y2VdbvRxleHU9aGxFRLXkh5BDGVbm5gAAhGeBMBl65XKmZ9sbNn4xxi3cbD7M02MpwZ3BpN4lG3xyFPsofbhXbMu8Z/1rlqfdul/KLaGmkllOYRj9Mhnumqw1f464dK948rgz5JxpeSQHN45GlMNjb717x6IeCCMa6gN+YX73M/LrkH1xZEhpjZ4YLugpHGquVl9m5Kq7AvcapkVEUsZt29JWB/dzq//bFG15ykd53wpP/8gddTTwV6i2vmLXLjDrfwO4NCLolYyD78vmdPsZRvlI4B0bslHerN7buJ938iWcaKg6NjrHMfZhO6BrvbLRbhSUQSKfgyXsAhaT/O1p1fM6KoFlWbHri9HfIwKocjXQkUDsT2u7U2+82oYHVvhthhCOlxlQyiUKr11Cj9Pzbqz11sulpr0D0rfChHOO81Ht3ax1ynL/nTQmNWCj4U4C0T9cjmUNU47gdGMEa0+tyv2s75/Xvo+qTrywdVqLDEviE+3Gxy3U+vX5MRrJipxK2OnUu/g/uanoLok7CA4LKQe7+ho6Vrb91/K/scyEdIvUlZ5A3LfP3DRWsE4LbKkYcwUy6ea7aEqdaEqd6ea7cwUybKkYsE4L3DRW3LfPlZ5AdIvUscyE1/K/Vrb9+ho6KQe7CA4LLok7uanou/g/2OnUipxKMRrJ+vX5xy3UE+3GDEvidVqLTrywvo+q75/Xyv2sa0+tdGMEU47gjmUN0T9c4U4CNWCjnTQmynL/3ax181HthHOO0rfCpr0D1sulbqz1j9Pzr11CyiUKlxlQhhCOVvht2oYHU2+8T2u7kUDscjXQIwKoi9HfWbHrKoFl1fM6/O1pAhaTgyXsQSKfbhSUvbLRO6BrMfZhNjrHaKg68iWcuJ93rN7bslHe4B0bRvlIdPsZ78vmlYyDNCLofwO4LjDrvmLXV6i2dTTw/8gd3wpPykd5FG15q//bB/dz29JWUsZtpkVEAvca5Kq7Vl9mHGquLugpjZ4YZEhpkH1xM/LrYX736gN+CCMax6Ieb717lMNjN45GeSQH5Jxp8rgzdK94f464mqw1MhnuYRj9kllOLaGmul/KlqfdZ/1rbMu8fbhXFPsoG3xypN4lwZ3B02MpbD7Mxi3cNn4xZ9sb5XKmMBl6hGeB5gAAGVbmh5BDRLXkaGxFeHU9vRxl2VdbQY3YbXtWG4ngarIrme3gejmbBfNLL/jWPc0JIY4bG+GEQwLr6kpGlzQfISMjM/4jb4EhOqiq' def invert(x): return ~x & 0xffffffff def decode_func(key, value): return (value & (invert(key + 1) + 1)) + (key & (invert(value + 1) + 1)) def checker(key): result = key for i in xrange(0, len(data), 4): value = struct.unpack('I', data[i:i+4])[0] result = decode_func(result, value) return result key = checker(0x7a2896bf) print 'The key is: %s' % key