Skip to content
Snippets Groups Projects
Commit cd198715 authored by Martin Nilsson's avatar Martin Nilsson
Browse files

koremutake

Rev: lib/modules/Crypto.pmod/koremutake.pmod:1.1
parent 3f86a3c2
No related branches found
No related tags found
No related merge requests found
...@@ -89,6 +89,7 @@ testfont binary ...@@ -89,6 +89,7 @@ testfont binary
/lib/modules/Crypto.pmod/des3_cbc.pike foreign_ident /lib/modules/Crypto.pmod/des3_cbc.pike foreign_ident
/lib/modules/Crypto.pmod/des_cbc.pike foreign_ident /lib/modules/Crypto.pmod/des_cbc.pike foreign_ident
/lib/modules/Crypto.pmod/idea_cbc.pike foreign_ident /lib/modules/Crypto.pmod/idea_cbc.pike foreign_ident
/lib/modules/Crypto.pmod/koremutake.pmod foreign_ident
/lib/modules/Crypto.pmod/randomness.pmod foreign_ident /lib/modules/Crypto.pmod/randomness.pmod foreign_ident
/lib/modules/Crypto.pmod/rsa.pike foreign_ident /lib/modules/Crypto.pmod/rsa.pike foreign_ident
/lib/modules/Crypto.pmod/testsuite.in foreign_ident /lib/modules/Crypto.pmod/testsuite.in foreign_ident
......
// $Id: koremutake.pmod,v 1.1 2003/04/07 15:15:24 nilsson Exp $
//! Quote from Koremutake home page @url{http://shorl.com/koremutake@}:
//!
//! In an attempt to temporarily solve the fact that human beings seem
//! to be inable to remember important things (such as their names, car
//! keys and seemingly random numbers with fourteen digits in 'em), we
//! invented Koremutake.
//!
//! It is, in plain language, a way to express any large number as a
//! sequence of syllables. The general idea is that word-sounding
//! pieces of information are a lot easier to remember than a sequence
//! of digits.
static constant table = ({
"BA", "BE", "BI", "BO", "BU", "BY", "DA", "DE",
"DI", "DO", "DU", "DY", "FA", "FE", "FI", "FO",
"FU", "FY", "GA", "GE", "GI", "GO", "GU", "GY",
"HA", "HE", "HI", "HO", "HU", "HY", "JA", "JE",
"JI", "JO", "JU", "JY", "KA", "KE", "KI", "KO",
"KU", "KY", "LA", "LE", "LI", "LO", "LU", "LY",
"MA", "ME", "MI", "MO", "MU", "MY", "NA", "NE",
"NI", "NO", "NU", "NY", "PA", "PE", "PI", "PO",
"PU", "PY", "RA", "RE", "RI", "RO", "RU", "RY",
"SA", "SE", "SI", "SO", "SU", "SY", "TA", "TE",
"TI", "TO", "TU", "TY", "VA", "VE", "VI", "VO",
"VU", "VY", "BRA", "BRE", "BRI", "BRO", "BRU", "BRY",
"DRA", "DRE", "DRI", "DRO", "DRU", "DRY", "FRA", "FRE",
"FRI", "FRO", "FRU", "FRY", "GRA", "GRE", "GRI", "GRO",
"GRU", "GRY", "PRA", "PRE", "PRI", "PRO", "PRU", "PRY",
"STA", "STE", "STI", "STO", "STU", "STY", "TRA", "TRE"
});
//! Encode an integer as a koremutake string.
string encrypt(int m) {
string c="";
while(m) {
c = table[m&127] + c;
m >>= 7;
}
return c;
}
//! Decode a koremutake string into an integer.
int decrypt(string c) {
int m;
c = upper_case(c);
while(sizeof(c)) {
if(sizeof(c)==1) error("Error in cryptogram.\n");
string w = c[..1];
c = c[2..];
if( (< 'R', 'T' >)[w[1]] ) {
if(!sizeof(c)) error("Error in cryptogram.\n");
w += c[..0];
c = c[1..];
}
int p = search(table, w);
if(p==-1) error("Error in cryptogram %O.\n", w);
m <<= 7;
m += p;
}
return m;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment