letmut message = String::new(); print!("Let me encrypt one more thing for you: "); std::io::stdout().flush().unwrap(); std::io::stdin().read_line(&mut message).unwrap();
if message.len() > 29 { println!("Woah! That's too long for me :^)"); return; }
msg = b"\x00"*28 + b"\n" sh.sendline(msg) sh.recvuntil(b"Let me encrypt one more thing for you: ") enc2 = long_to_bytes(int(sh.recvline().strip().decode(),16)) key_pre = xor(enc2,msg)
print(len(key_pre)) print(len(enc_flag))
for i in trange(256): for j inrange(256): for k inrange(256): key = key_pre + long_to_bytes(i)+long_to_bytes(j)+long_to_bytes(k) dec = AES.new(key, AES.MODE_GCM, nonce=nonce1)
f1 = "" for i in c1: if(i == "*"): f1 += "******" continue f1 += bin(table.index(i))[2:].zfill(6)
f2 = "" for i in c2: if(i == "*"): f2 += "******" continue f2 += bin(table.index(i))[2:].zfill(6) print(f1[8:]) print(f2)
final = "0000010010110000111110000101101100110010010111111100101011001110111101000111011011110011100100100110011100000101001010001110001100101101110010111100001101000101011110011011111010011000011001100101101000000111101100110110001010010110100011001010111011110110010110001001100010010000111011111100101001001001010001111110111010010011101100111011010010010001100010011110111111101010000001010100111011011100110100001110100010100101100100111010110101100010111111111011110111000100110100111000010001000110001111101011001100001111" print(int(final,2))
from tqdm import * from hashlib import * from base64 import *
p = 0xffffffff00000001000000000000000000000000ffffffffffffffffffffffff K = GF(p) a = K(0xffffffff00000001000000000000000000000000fffffffffffffffffffffffc) b = K(0x5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b) E = EllipticCurve(K, (a, b)) G = E(0x6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296, 0x4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5) E.set_order(0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551 * 0x1)
t = "b0f85b325fcacef476f392670528e32dcbc34579be98665a07b362968caef6589890efca4947ee93b3b49189efea054edcd0e8a593ad62ffbdc4d384463eb30f"
from base64 import * from Crypto.Util.number import *
p = 62899910107538091753472605731958716431532429784101879766564879776512571948297970028879774548189532173352114204695025969537124428037066379787090737034605327 d = 47301141220363818814201640121058873711332982879724793113526901098081948819591
library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; use std.textio.all; use work.rng.all; use work.stdio.all; use work.secret.FLAG;
entity pwdhdl is end pwdhdl;
architecture Behavioral of pwdhdl is constant PASSWORD_SIZE : integer := 32; constant SEED_SIZE : integer := 8; constant SECRET_SIZE : INTEGER := 20; constant DB_SIZE : INTEGER := 10; type FSM_STATE is (INITIALIZE, STORE_FLAG, STORE_FLAG_WAIT, MENU, STORE, STORE_WAIT, GET, FULL); type DB_ENTRY isrecord secret : STRING(1to SECRET_SIZE); password : STRING(1to PASSWORD_SIZE); endrecord; type DB isarray(0to DB_SIZE-1) of DB_ENTRY;
signal CLK : STD_LOGIC := '0'; signal data : STD_LOGIC_VECTOR(PASSWORD_SIZE*4-1downto0); signal seed : STD_LOGIC_VECTOR(0to SEED_SIZE*8-1); signal taps : STD_LOGIC_VECTOR(0to SEED_SIZE*8-1); signal reset, enable, done : STD_LOGIC; signal database : DB := (others => ((others => '0'), (others => '0')));
begin password_generator: pwd_gen genericmap( STATE_SIZE => SEED_SIZE*8, OUTPUT_SIZE => PASSWORD_SIZE*4 ) portmap( CLK => CLK, RESET => reset, ENABLE => enable, SEED => seed, TAPPED => taps, VALID => done, DATA => data ); clock: process begin CLK <= not CLK; waitfor10 ns; endprocess; interface: process(CLK) variable state : FSM_STATE := INITIALIZE; variable db_index : NATURAL := 1; variable selection : STRING(1to1); variable secret : STRING(1to SECRET_SIZE); variable password : STRING(1to PASSWORD_SIZE); variable query_successful : BOOLEAN := false; begin if rising_edge(CLK) then state := state; reset <= '0'; enable <= '0'; case state is when INITIALIZE => enable <= '0'; reset <= '1'; seed <= read_urandom(SEED_SIZE); taps <= read_urandom(SEED_SIZE); taps(SEED_SIZE*8-1) <= '1'; state := STORE_FLAG;
when STORE_FLAG => secret := FLAG; enable <= '1'; state := STORE_FLAG_WAIT; when STORE_FLAG_WAIT => if done = '1'then password := to_hstring(unsigned(data)); database(0) <= (secret, password); state := MENU; write_stdout("+--------------------------------------------+"); write_stdout("| Welcome to pwdHDL, the password pawn shop. |"); write_stdout("+--------------------------------------------+"); write_stdout(""); else state := STORE_FLAG_WAIT; endif;
when MENU => write_stdout("Please select one of the following options:"); write_stdout("1) Offer a secret"); write_stdout("2) Retrieve a secret"); selection := read_stdin(1); write_stdout(""); case (selection) is when"1" => state := STORE; when"2" => state := GET; whenothers => state := MENU; endcase; when STORE => write_stdout("We will lend you a password in exchange for a collateral."); write_stdout("Please tell us a secret (at most " & integer'image(SECRET_SIZE) & " characters):"); secret := read_stdin(SECRET_SIZE); write_stdout(""); enable <= '1'; state := STORE_WAIT; when STORE_WAIT => if done = '1'then password := to_hstring(unsigned(data)); write_stdout("Your password is: " & password); write_stdout(""); database(db_index) <= (secret, password); db_index := db_index + 1; state := FULL when db_index >= DB_SIZE else MENU; else state := STORE_WAIT; endif;
when GET => write_stdout("Please return your password to retrieve your secret:"); password := read_stdin(PASSWORD_SIZE); write_stdout(""); query_successful := false; for I in0to DB_SIZE-1loop if database(I).password = password andnot query_successful then if password /= "00000000000000000000000000000000"then write_stdout("Thank you for returning our valuable entropy to us."); write_stdout("Your secret is: " & database(I).secret); else write_stdout("Nothing? Really?"); endif; query_successful := true; endif; endloop; ifnot query_successful then write_stdout("What is this? This is not one of our passwords."); endif; write_stdout(""); state := FULL when db_index >= DB_SIZE else MENU; when FULL => write_stdout("We will not accept any additional secrets at this time."); write_stdout(""); state := GET; endcase; endif; endprocess; end Behavioral;
architecture Behavioral of pwd_gen is signal running : BOOLEAN := false; signal taps : STD_LOGIC_VECTOR(0to STATE_SIZE-1); signal state : STD_LOGIC_VECTOR(0to STATE_SIZE-1); signal outbit : STD_LOGIC; begin outbit <= state(STATE_SIZE-1);
process(CLK) is variable counter : INTEGER; variable xbit : STD_LOGIC; begin if RESET = '1'then state <= SEED; taps <= TAPPED; running <= false; counter := 0; VALID <= '0'; elsif rising_edge(CLK) then VALID <= '0'; if ENABLE = '1'then running <= true; endif; if running then state <= (xor (state and taps)) & state(0to STATE_SIZE-2); DATA <= DATA(OUTPUT_SIZE-2downto0) & outbit; counter := counter + 1; if counter >= OUTPUT_SIZE then VALID <= '1'; running <= false; counter := 0; endif; endif; endif; endprocess; end Behavioral;
L = [] for i inrange(64): temp = s0_bin[i:] + s1_bin[:i] L.append(list(map(int,temp))) L = Matrix(GF(2),L) B = vector(GF(2),list(map(int,s1_bin))) mask = L.solve_right(B) print(mask)
tap = mask[1:] t = "" for i inrange(128): temp1 = list(map(int,init[:-1])) temp2 = int(init[-1])
sum1 = temp2 for j inrange(len(temp1)): sum1 -= (int(temp1[j]) * int(tap[j])) t = (str(sum1 % 2)) + t init = t[0] + init[:-1]
print(hex(int(t,2)).upper())
temp = list(map(int,t))[64:]
f = "" for i inrange(128): tt = vector(Zmod(2),temp)*mask f += str(tt) temp = temp[1:] + [tt] print(hex(int(f,2)))
L = [] for i inrange(64): temp = s0_bin[i:] + s1_bin[:i] L.append(list(map(int,temp))) L = Matrix(GF(2),L) B = vector(GF(2),list(map(int,s1_bin))) mask = L.solve_right(B) print(mask)
tap = mask[1:] t = "" for i inrange(128): temp1 = list(map(int,init[:-1])) temp2 = int(init[-1])
sum1 = temp2 for j inrange(len(temp1)): sum1 -= (int(temp1[j]) * int(tap[j])) t = (str(sum1 % 2)) + t init = t[0] + init[:-1]
print(hex(int(t,2)).upper())
temp = list(map(int,t))[64:]
f = "" for i inrange(128): tt = vector(Zmod(2),temp)*mask f += str(tt) temp = temp[1:] + [tt] print(hex(int(f,2)))