All pastes #468360 Raw Edit

Untitled

public text v1 · immutable
·published 2007-05-03 01:55 UTC
rendered paste body
bool key_check (const u8 *key) {
    u32 v = 3;
    u8  i = 0;
    while (i < 12)
	v += key [i++] ^ v * 2;
    return key [12] == v % 10;
}

inline u8 key_product (const u8 *key) {
    return key [1];
}

u32 key_public (const u8 *key) {
    u8 pub [8];
    u8 i = 2, j = 0;
    while (i < 10)
	pub [j++] = key [i++];
    return toint (pub, 8);
}

inline u32 key_private (const u8 *key) {
    return toint (key + 10, 3);
}

void key_decode (const u8 *key, u8 *deckey) {
    u8  seq [] = {6, 0, 2, 9, 3, 11, 1, 7, 5, 4, 10, 8};
    u8  i      = 11;
    u32 v      = 330078017;
    do {
	seq [i] = key [seq [i]];
	if (seq [i] < 8) {
	    seq [i] ^= v & 7;
	    v >>= 3;
	} else
	    seq [i] ^= i & 1;
	deckey [i] = seq [i];
    } while (i--);
}