/* * Vernash v0.1 * Coded by Shen139 07-02-2006 * shen139 (at_) eviltime [.dot.] com * * Stream cipher based on the Vernam cipher and Variable-Length Hashes * * * Compile with: $ gcc vernash.c -o vernash * * * Usage for encrypting a text: ./vernash * or * Usage for decrypting a text: ./vernash -d * or * Usage for generating an Hash: ./vernash -g * * * Usage examples: * * (Encrypt "1234567890987654321" with password "abc") $ ./vernash 1234567890987654321 abc Text: ---1234567890987654321--- Password: ---abc--- Encrypted-Text: ---2;D>>:OKE>AI=K@79>F--- * * (DeCrypt "2;D>>:OKE>AI=K@79>F" with password "abc") $ ./vernash -d "2;D>>:OKE>AI=K@79>F" abc Text: ---2;D>>:OKE>AI=K@79>F--- Password: ---abc--- Decrypted-Text: ---1234567890987654321--- * * (Generate an hash of 50 bytes for "a") $ ./vernash -g a 50 Hash(50) for ---a---: ---tmqiyiburudwvokwyhdwwuskwmrylcetzivzaaiubpzpqhnwce--- * * (Generate an hash of 50 bytes for "aa") $ ./vernash -g aa 50 Hash(50) for ---aa---: ---wvblxzhpqevedbbwumlaxlywvnrvtfnovijwpnzuzhirmlxztx--- * * (Generate an hash of 30 bytes for "test123456789") $ ./vernash -g test123456789 30 Hash(30) for ---test123456789---: ---xtjslsxkkokdlynprivlkjyqsughhg--- * * * * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ /* UnComment the following line to enable debugs */ //#define DEBUG #include #include #include void usage(char* arg0) { printf("Usage for encrypting a text: %s \n or\n",arg0); printf("Usage for decrypting a text: %s -d \n or\n",arg0); printf("Usage for generating an Hash: %s -g \n",arg0); exit(0); } /* RotCharUp Examples * RotCharUp('a'+1,'a','z'); => 'b' * RotCharUp('a'+26,'a','z'); => 'a' * RotCharUp('a'+100,'a','z'); => 'w' */ char RotCharUp(unsigned int value, char lBound, char rBound) { while(value>rBound) value=(unsigned int)lBound + (value-rBound-1); return (char)value; } /* RotCharDown Examples * RotCharDown('a'-1,'a','z'); => 'z' * RotCharDown('a'-26,'a','z'); => 'a' * RotCharDown('a'-100,'a','z'); => 'e' */ char RotCharDown(int value, char lBound, char rBound) { while(valuetext[c-1]) ? text[c]-text[c-1] : text[c-1]-text[c]; if(c) avg /= textLen; return avg+1; } int charWSum(char* text) { int c; int textLen = strlen(text); int sum = 0; for(c=0;c 0xABC) sum = sum - ((text[c] * ((c*10)%0x10)) % 0xABC); else sum += text[c] * ((c*10)%0x12); return sum; } /* hashum * Variable hashes generator * * Hashes Examples * aa(50) wvblxzhpqevedbbwumlaxlywvnrvtfnovijwpnzuzhirmlxztx bb(50) wanwdkdkqcmtnzwnpbhhlhdkzkdsyrkonuezejrdgvuqyyajzc ab(50) rafvlxzsqktaiknughvkonjqadmrtozjxnhqtcsesqzipyobrn ba(50) rybohexdwivajergruxenyjvafibvzsakgeqxrvnrtodlwhexh aba(50) nikwjervknzkvdrktbnmlejypaxqqmjthszbyqeccuiwwlnztr baa(50) pmwgbltcbmxetmtrletwluytivjnfgakryaauebqqkvjhsgyay test(35) xyuglkhsvoveuvxiszegxkvxkdqbjaqhbfg shen139(25) rufvdrpkocxkiacadinktxqek * */ char* hashum(char* word, int length) { int wordLen = strlen(word); char* hash = (char*)malloc(length+1); int i; unsigned int curC=0; int hashLen; if(hash == NULL || wordLen<1) return NULL; hash[0]='\0'; for(i=0;i