commit 59561bf6eb4617d942bb52504322ecd5bb761bfa
parent 0ca2f31561ddda0594dbf33e98eabbd3aee2cef2
Author: finwo <finwo@pm.me>
Date: Thu, 10 Aug 2017 23:33:45 +0200
Bugfix + removed sign
Diffstat:
6 files changed, 24 insertions(+), 43 deletions(-)
diff --git a/README.md b/README.md
@@ -0,0 +1,7 @@
+# cdeps / cryptest
+
+A self-made cryptography algorithm. This is an example implementation of the scheme idea's promoted [here](https://gist.github.com/finwo/ebfd96e35eeffc19dc25f5afc11b9c98). The algorithm HAS NOT been tested for actual cryptographic strength, do not assume this provides anything more than obfuscation.
+
+---
+
+Keys are composed of 2 unsigned 32-bit integers, the multiplicand and the modulator. The only restriction on these numbers is that the modulator must be >=128, which results in ((2**32)-128)*(2**32) = 18446743523953737728 possible keys. Padding is forced to further randomize the output and has no structural restrictions.
diff --git a/inc/base.h b/inc/base.h
@@ -4,6 +4,7 @@ extern "C" {
#define MIN(a,b) (((a)<(b))?(a):(b))
#define MAX(a,b) (((a)>(b))?(a):(b))
+#define ROT(s,a) ((s<<a)|(s>>(sizeof(s)-a)))
unsigned int atoui( char *in );
diff --git a/src/decrypt.c b/src/decrypt.c
@@ -25,13 +25,12 @@ int decrypt( unsigned int mult, unsigned int modulo, unsigned int padding ) {
}
while( 1 ) {
+
+ // Handle stdin
c = fgetc(stdin);
if(c==EOF) break;
- seed *= mult;
- seed += c;
- seed = seed % modulo;
- obuf = obuf << 7;
- obuf &= ~127;
+ seed = ((seed*mult)+c)%modulo;
+ obuf = (obuf%(1<<obuf_len))<<7;
obuf |= seed%128;
obuf_len += 7;
if(obuf_len>=8) {
@@ -39,7 +38,7 @@ int decrypt( unsigned int mult, unsigned int modulo, unsigned int padding ) {
obuf_len-=8;
}
}
-
+
return 0;
}
diff --git a/src/encrypt.c b/src/encrypt.c
@@ -42,34 +42,23 @@ int encrypt( unsigned int mult, unsigned int modulo, unsigned int padding ) {
if ( (c=fgetc(stdin)) == EOF ) {
flags &= ~2;
} else {
+ ibuf = ibuf % ( 1 << ibuf_len );
ibuf = ibuf << 8;
- ibuf &= ~255;
ibuf |= c;
ibuf_len += 8;
}
}
- // Pre-step seed
- seed *= mult;
-
- // Fetch input
- c = ( (ibuf%(1<<ibuf_len)) << 7 ) >> ibuf_len;
+ // Fetch number to encode
+ c = ((ibuf<<7)>>ibuf_len)%128;
ibuf_len -= 7;
- // Try the fast method
- e = ( ((seed+c)%modulo)%128 ) - c;
-
// Feedback-based encoding
- if( ( (seed+e)%modulo)%128 != c ) {
- e = 0;
- while( ( (seed+e)%modulo)%128 != c ) e++;
- }
-
- // Output
- fputc( e, stdout );
-
- // Post-step seed
+ e = 0;
+ seed = seed * mult;
+ while( ((seed+e)%modulo)%128 != c ) e++;
seed = (seed+e)%modulo;
+ fputc( e, stdout );
// EOF detection
if( ibuf_len <= 0 && !(flags&2) ) {
diff --git a/src/main.c b/src/main.c
@@ -18,7 +18,6 @@ int usage( char *name ) {
" -d Decrypt stdin\n"
" -e Encrypt stdin\n"
" -h Show this usage\n"
- " -s Output sign for stdin\n"
" -t Set the multiplicand (default: 13)\n"
" -m Set the modulo (>=128) (default: 66066)\n"
" -p Set the padding in bytes (>=1) (default: 1)\n");
@@ -31,8 +30,11 @@ int main( int argc, char **argv ) {
unsigned int mult = 13, modulo = 66066, padding = 1;
char mode = 0;
+ unsigned long long vercode = 0;
+
+ setvbuf(stdout,NULL,_IONBF,0);
- while((opt=getopt(argc,argv,"edsht:m:p:"))!=-1) {
+ while((opt=getopt(argc,argv,"deht:m:p:"))!=-1) {
switch(opt) {
case 'e':
mode = 1;
@@ -40,9 +42,6 @@ int main( int argc, char **argv ) {
case 'd':
mode = 2;
break;
- case 's':
- mode = 3;
- break;
case 't':
mult = atoui( optarg );
break;
@@ -71,7 +70,6 @@ int main( int argc, char **argv ) {
switch(mode) {
case 1: return encrypt( mult, modulo, padding );
case 2: return decrypt( mult, modulo, padding );
- case 3: return sign( mult, modulo );
}
usage( *argv );
diff --git a/src/sign.c b/src/sign.c
@@ -1,13 +0,0 @@
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include "base.h"
-
-int sign( unsigned int mult, unsigned int modulo ) {
-
-}
-
-#ifdef __cplusplus
-} // extern "C"
-#endif