#py2 import string import random from secret import flag,b_char
defencode(s): res='' binstr=[ bin(ord(s[i])).replace('0b','').zfill(8) for i inrange(len(s))] p1=len(binstr) // 3 p2=len(binstr) % 3 part1 = binstr[0:3*p1] for i inrange(p1): str_p1=binstr[i*3]+binstr[i*3+1]+binstr[i*3+2] tmp_str = [str_p1[x: x + 6] for x in [0, 6, 12, 18]] tmp_res = [b_char[int(x,2)]for x in tmp_str] res+=''.join(tmp_res)
if p2: part2 = binstr[3*p1:] str_p2 = ''.join(part2)+(3-p2)*'0'*8 tmp_str = [str_p2[x: x + 6] for x in [0, 6, 12, 18]][:p2+1] tmp_res = [b_char[int(x,2)]for x in tmp_str] res+=''.join(tmp_res) res +='='*(3-p2) return res m1=random.sample(list(b_char),50) print''.join(m1) print encode(m1) print encode(flag) # rTcb1BR8YVW2EOUjweXpIiLt5QCNg7ZAsD9muq3ylMhvofnx/P # 2Br9y9fcu97zvB2OruZv0D3Bwhbj0uNQnvfdtC2TwAfPrdBJ3xeP4wNn0hzLzCVUlRa= # tCvM4R3TzvZ7nhjBxSiNyxmP28e7qCjVxQn91SRM3gBKzxQ=
Let be the characteristic of the base ring this polynomial is defined over: N = self.base_ring().characteristic(). This method returns small roots of this polynomial modulo some factor of with the constraint that . Small in this context means that if is a root of modulo then . This is either provided by the user or the maximum is chosen such that this algorithm terminates in polynomial time. If is chosen automatically it is . The algorithm may also return some roots which are larger than X. This algorithm in this context means Coppersmith’s algorithm for finding small roots using the LLL algorithm. The implementation of this algorithm follows Alexander May’s PhD thesis referenced below.
INPUT:
X – an absolute bound for the root (default: see above)
beta – compute a root mod where is a factor of N and ( Default: 1.0, so . )
epsilon – the parameter described above. (Default: )
Don Coppersmith. Finding a small root of a univariate modular equation. In Advances in Cryptology, EuroCrypt 1996, volume 1070 of Lecture Notes in Computer Science, p. 155–165. Springer, 1996. http://cr.yp.to/bib/2001/coppersmith.pdf
c = int(c3.nth_root(3) % (2^2001)) pdf = int(c %2^1200 // 2^400) x = var('x') f = 2^1200 * pdf - c * x + 2^1201 * x^2 + 2^400 * x * pdf flag2 = int(f.roots()[0][0]) padding = pdf // flag2 l2b(padding) # b'1_l0v3_9ou}'