From cd198715a96ffa3f17ccb632638e698ebccf5d66 Mon Sep 17 00:00:00 2001 From: Martin Nilsson <mani@lysator.liu.se> Date: Mon, 7 Apr 2003 17:15:24 +0200 Subject: [PATCH] koremutake Rev: lib/modules/Crypto.pmod/koremutake.pmod:1.1 --- .gitattributes | 1 + lib/modules/Crypto.pmod/koremutake.pmod | 65 +++++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 lib/modules/Crypto.pmod/koremutake.pmod diff --git a/.gitattributes b/.gitattributes index 0283f3b959..afae301c8f 100644 --- a/.gitattributes +++ b/.gitattributes @@ -89,6 +89,7 @@ testfont binary /lib/modules/Crypto.pmod/des3_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/koremutake.pmod foreign_ident /lib/modules/Crypto.pmod/randomness.pmod foreign_ident /lib/modules/Crypto.pmod/rsa.pike foreign_ident /lib/modules/Crypto.pmod/testsuite.in foreign_ident diff --git a/lib/modules/Crypto.pmod/koremutake.pmod b/lib/modules/Crypto.pmod/koremutake.pmod new file mode 100644 index 0000000000..8acd98f259 --- /dev/null +++ b/lib/modules/Crypto.pmod/koremutake.pmod @@ -0,0 +1,65 @@ +// $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; +} -- GitLab