aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSathariel <sathariel@cock.li>2018-06-20 11:47:12 -0500
committerSathariel <sathariel@cock.li>2018-06-20 11:47:12 -0500
commit384419573aca4be1ee32f0f16d41fb9460698d67 (patch)
treee3f3e2b8d22176aed000ee5092bdc59325cdf484
parent94d8a69b6828b086a48d9014ff640c2b951b28e8 (diff)
downloadathame-384419573aca4be1ee32f0f16d41fb9460698d67.zip
athame-384419573aca4be1ee32f0f16d41fb9460698d67.tar
Implemented CipherSaber-2HEADmaster
-rw-r--r--README5
-rw-r--r--main.c24
2 files changed, 19 insertions, 10 deletions
diff --git a/README b/README
index b14a703..0e4433c 100644
--- a/README
+++ b/README
@@ -1,12 +1,13 @@
-Implementation of CipherSaber ( http://ciphersaber.gurus.org/ )
+Implementation of CipherSaber 1 & 2 ( http://ciphersaber.gurus.org/ )
Usage:
-athame [-e | -d] [-k key] [-o file] file
+athame [-e | -d] [-r num] [-k key] [-o file] file
Options:
-e Encrypt mode (default)
-d Decrypt mode
+-r Number of rounds when permutate. Default is 20, set this to 1 to use CipherSaber-1
-k Key used to encrypt/decrypt. It will be prompted if this is ommited
-o Output file. It uses standard output by default
diff --git a/main.c b/main.c
index dd6de1e..efd5b94 100644
--- a/main.c
+++ b/main.c
@@ -18,14 +18,16 @@ swap(int i, int j)
}
void
-ksa(char *key, size_t len)
+ksa(char *key, size_t len, long int rounds)
{
- int i, j = 0;
+ int i, r, j = 0;
for (i = 0; i < 256; i++)
S[i] = i;
- for (i = 0; i < 256; i++) {
- j = (j + S[i] + key[i % len]) & 255;
- swap(i, j);
+ for (r = 0; r < rounds; r++) {
+ for (i = 0; i < 256; i++) {
+ j = (j + S[i] + key[i % len]) & 255;
+ swap(i, j);
+ }
}
}
@@ -64,8 +66,8 @@ getIV(FILE *fp)
void
usage(char *name)
{
- fprintf(stderr, "usage: %s [-e | -d] [-k key] [-o file] file\n",
- name);
+ fprintf(stderr, "usage: %s [-e | -d] [-r num] [-k key]"
+ "[-o file] file\n", name);
exit(1);
}
@@ -73,6 +75,7 @@ int
main(int argc, char *argv[])
{
int c;
+ unsigned int rounds = 20;
char key[KEYSIZE + 10] = "", mode = 'e', *out;
unsigned char *iv;
size_t len;
@@ -90,6 +93,11 @@ main(int argc, char *argv[])
case 'k':
strncpy(key, EARGF(usage(argv0)), KEYSIZE);
break;
+ case 'r':
+ rounds = strtol(EARGF(usage(argv0)), NULL, 10);
+ if (rounds < 1)
+ usage(argv0);
+ break;
case 'o':
out = EARGF(usage(argv0));
break;
@@ -124,7 +132,7 @@ main(int argc, char *argv[])
iv = (mode == 'e') ? genIV(outfile) : getIV(infile);
len = strlen(key);
memmove(key + len, iv, 10);
- ksa(key, len + 10);
+ ksa(key, len + 10, rounds);
while ((c = getc(infile)) != EOF)
putc(c ^ rand4(), outfile);