All pastes #463590 Raw Edit

Something

public text v1 · immutable
#463590 ·published 2007-04-29 00:47 UTC
rendered paste body
void pack (u16 number, u8 size, u8 *buf, u8 *pos) {
  while (size--) {
      buf [(*pos)++] = number % 256;
      number /= 256;
  }
}

u32 toint (const u8 *ls, u8 size) {
    u8  i = 0;
    u32 n = 0;
    while (i < size)
	n = (n * 10) + ls [i++];
    return n;
}

bool key_check (const u8 *ls) {
    u32 v = 3;
    u8  i = 0;
    while (i < 12)
	v += ls [i++] ^ v * 2;
    return ls [12] == v % 10;
}

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

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

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