def encode_plain(s): r = [] s_bytes = [ord(c) for c in s] crc = crc_32(s_bytes) # length, twice r.append(len(s)) r.append(len(s)) # encode CRC as LE r.extend([(crc >> i) & 255 for i in range(0, 32, 8)]) # payload, plaintext r.extend(s_bytes) return r
def encode_pw(pw): r = [] pw_bytes = [ord(c) for c in pw] encrypted_pw = encrypt(pw) # CRC and length are from plaintext crc = crc_32(pw_bytes) # length, twice r.append(len(pw)) r.append(len(pw)) # encode CRC as LE r.extend([(crc >> i) & 255 for i in range(0, 32, 8)]) # payload, AES encrypted r.extend(encrypted_pw) return r