#define eilblocksize 32
#define eilkeyblocksize 32
#define u8 unsigned char
unsigned char original_key_state[eilkeyblocksize];
unsigned char keybox[eilkeyblocksize] = {0};
unsigned char permutebox[eilkeyblocksize];
unsigned char permutebilebox[eilkeyblocksize];
int permutestate = 0;
#if 0
typedef union {
unsigned char a:1;
unsigned char b:1;
unsigned char c:1;
unsigned char d:1;
unsigned char e:1;
unsigned char f:1;
unsigned char g:1;
unsigned char h:1;
} envy_byte;
/*
envybox[i].a = getbit(key[i], 1);
envybox[i].b = getbit(key[i], 2);
envybox[i].c = getbit(key[i], 3);
envybox[i].d = getbit(key[i], 4);
envybox[i].e = getbit(key[i], 5);
envybox[i].f = getbit(key[i], 6);
envybox[i].g = getbit(key[i], 7);
envybox[i].h = getbit(key[i], 8);
*/
unsigned char getbit(unsigned char c, int n) {
return c=(c&(1<<n))>>n;
}
envy_byte envybox[eilkeyblocksize];
unsigned char bean_a[eilkeyblocksize];
unsigned char bean_b[eilkeyblocksize];
unsigned char bean_c[eilkeyblocksize];
unsigned char bean_d[eilkeyblocksize];
unsigned char bean_e[eilkeyblocksize];
unsigned char bean_f[eilkeyblocksize];
unsigned char bean_g[eilkeyblocksize];
unsigned char bean_h[eilkeyblocksize];
void wrap_beans_from_a_to_h()
{
int i;
for ( i = 0; i < eilkeyblocksize; i++ )
{
bean_a = envybox[i].e
envybox[i].d = getbit(key[i], 2);
envybox[i].f = getbit(key[i], 3);
envybox[i].d = getbit(key[i], 4);
envybox[i].a = getbit(key[i], 5);
envybox[i].h = getbit(key[i], 6);
envybox[i].b = getbit(key[i], 7);
envybox[i].g = getbit(key[i], 8);
}
}
void fill_key_into_envybox(unsigned char* key)
{
int i;
for ( i = 0; i < eilkeyblocksize; i++ )
{
envybox[i].a = getbit(key[i], 1);
envybox[i].b = getbit(key[i], 2);
envybox[i].c = getbit(key[i], 3);
envybox[i].d = getbit(key[i], 4);
envybox[i].e = getbit(key[i], 5);
envybox[i].f = getbit(key[i], 6);
envybox[i].g = getbit(key[i], 7);
envybox[i].h = getbit(key[i], 8);
}
}
void bean
#endif
void bean_mixa(unsigned char *key, int current, int addition)
{
if ( key[current] > key[current+addition] )
key[current] -= key[current+addition];
permutebox[permutestate++] = key[current] ^ key[current+addition];
}
void bean_mixb(unsigned char *key, int current, int addition)
{
if ( key[current] < key[current+addition] )
key[current] += key[current+addition];
permutebox[permutestate++] = key[current] ^ key[current+addition];
}
void bean_mix_bilea(unsigned char *key, int current, int addition)
{
unsigned char bilebyte = key[current];
bilebyte ^= key[current] + permutebox[current] - (key[current+addition] ^ permutebox[current]);
if ( key[current] > key[current+addition] )
key[current] ^= permutebox[current] ;
permutebilebox[permutestate++] = key[current] ^ bilebyte;
}
void bean_mix_bileb(unsigned char *key, int current, int addition)
{
unsigned char bilebytea = key[current];
unsigned char bilebyteb = key[current+addition];
bilebytea ^= key[current] - permutebox[current] + (key[current+addition] ^ permutebox[current+addition]);
bilebyteb ^= key[current] + permutebox[current] + (key[current+addition] + permutebox[current]);
if ( key[current] > key[current+addition] )
key[current] -= bilebyteb;
permutebilebox[permutestate++] = key[current] ^ bilebytea ^ bilebyteb;
}
void mix_and_permute_keyblock(unsigned char* key)
{
int i, j=0;
for (i = 0; i < eilkeyblocksize; i++)
original_key_state[i] = key[i];
for (i = 0; i < eilkeyblocksize; i++) {
bean_mixa(key, i, j);
bean_mixb(key, i, j);
bean_mix_bilea(key, i, j);
bean_mix_bileb(key, i, j);
j++;
}
}
void mix_and_permute_permuteblock(unsigned char* key)
{
int i;
for (i = 0; i < eilkeyblocksize; i++) {
permutebox[i] ^= key[i];
}
}
void mix_and_permute_permutebileblock(unsigned char* key)
{
int i;
for (i = 0; i < eilkeyblocksize; i++) {
permutebilebox[i] ^= original_key_state[i];
}
}
void interate_and_permute_key_into_keybox(unsigned char* key)
{
int i;
for (i = 0; i < eilkeyblocksize; i++) {
keybox[i] = key[i] ^ permutebox[i] ^ permutebilebox[i] ^ original_key_state[i];
}
}
void put_keystate(u8* key)
{
mix_and_permute_keyblock(key);
mix_and_permute_permuteblock(key);
mix_and_permute_permutebileblock(key);
interate_and_permute_key_into_keybox(key);
}
#define mix_over_boxes(inblock, outblock, blocksize) \
{ int i; int j; \
for (j=0; j < blocksize; j++ ) { \
for ( i = 0; i < eilkeyblocksize; i++) \
{ \
inblock[i] ^= keybox[i]; \
} \
for ( i = 0; i < eilkeyblocksize; i++) \
{ \
inblock[i] ^= permutebox[i]; \
} \
for ( i = 0; i < eilkeyblocksize; i++) \
{ \
inblock[i] ^= original_key_state[i]; \
} \
for ( i = 0; i < eilkeyblocksize; i++) \
{ \
inblock[i] ^= permutebilebox[i]; \
} \
outblock[i] = inblock[i]; \
} \
}
#define unmix_over_boxes(inblock, outblock, blocksize) \
{ int i; int j;\
for (j=0; j < blocksize; j++ ) { \
for ( i = 0; i < eilkeyblocksize; i++) \
{ \
inblock[i] ^= permutebilebox[i]; \
} \
for ( i = 0; i < eilkeyblocksize; i++) \
{ \
inblock[i] ^= original_key_state[i]; \
} \
for ( i = 0; i < eilkeyblocksize; i++) \
{ \
inblock[i] ^= permutebox[i]; \
} \
for ( i = 0; i < eilkeyblocksize; i++) \
{ \
inblock[i] ^= keybox[i]; \
} \
outblock[i] = inblock[i]; \
} \
}
void mix_(u8 *block, u8 *outblock, int blocksize)
{
mix_over_boxes(block, outblock, blocksize)
}
void unmix_(u8 *block, u8 *outblock, int blocksize)
{
unmix_over_boxes(block, outblock, blocksize)
}
void encrypt_block(unsigned char* block, unsigned char* outblock, int blocksize)
{
mix_(block, outblock, blocksize);
}
void decrypt_block(unsigned char* block, unsigned char* outblock, int blocksize)
{
unmix_(block, outblock, blocksize);
}
#include <stdio.h>
#include <string.h>
int main()
{
unsigned char* key;
unsigned char *string = NULL;
char n = 0;
int i = 0;
int j = 0;
key = (unsigned char*) malloc(eilkeyblocksize);
memset(key, 0, eilkeyblocksize);
init_system();
gather_random_fast(key, eilkeyblocksize);
put_keystate(key);
string = (unsigned char*) malloc(1+1);
fprintf(stderr, "enter plaintext[]:");
nullru:
n = getchar();
if ( n == '\n') goto pillmill;
string = (char*) realloc(string, ++j);
string[j-1] = n;
goto nullru;
pillmill:
encrypt_block(string, string, j);
string[j+1] = '\0';
fprintf(stderr, "encrypted: %s\n", string);
decrypt_block(string, string, j);
string[j+1] = '\0';
fprintf(stderr, "decrypted: %s\n", string);
close_system();
return 0;
}
-----------------------------------------------------------------------------------------------------------
#define eilblocksize 32
#define eilkeyblocksize 32
#define u8 unsigned char
unsigned char original_key_state[eilkeyblocksize];
unsigned char keybox[eilkeyblocksize] = {0};
unsigned char permutebox[eilkeyblocksize];
unsigned char permutebilebox[eilkeyblocksize];
int permutestate = 0;
typedef union {
unsigned char a:1;
unsigned char b:1;
unsigned char c:1;
unsigned char d:1;
unsigned char e:1;
unsigned char f:1;
unsigned char g:1;
unsigned char h:1;
} envy_byte;
/*
envybox[i].a = getbit(key[i], 1);
envybox[i].b = getbit(key[i], 2);
envybox[i].c = getbit(key[i], 3);
envybox[i].d = getbit(key[i], 4);
envybox[i].e = getbit(key[i], 5);
envybox[i].f = getbit(key[i], 6);
envybox[i].g = getbit(key[i], 7);
envybox[i].h = getbit(key[i], 8);
*/
unsigned char getbit(unsigned char c, int n) {
return c=(c&(1<<n))>>n;
}
envy_byte envybox[eilkeyblocksize];
void bean_mixa(unsigned char *key, int current, int addition)
{
if ( key[current] > key[(current+addition)%eilkeyblocksize] )
key[current] ^= key[(current+addition)%eilkeyblocksize];
permutebox[permutestate++] = key[current];
}
void bean_mixb(unsigned char *key, int current, int addition)
{
if ( key[current] < key[(current+addition)%eilkeyblocksize] )
key[current] ^= key[(current+addition)%eilkeyblocksize];
permutebox[permutestate++] = key[current];
}
void bean_mix_bilea(unsigned char *key, int current, int addition)
{
if ( key[(current+addition)%eilkeyblocksize] > key[current] )
key[(current+addition)%eilkeyblocksize] ^= key[current];
permutebilebox[permutestate++] = key[(current+addition)%eilkeyblocksize];
}
void bean_mix_bileb(unsigned char *key, int current, int addition)
{
if ( key[(current+addition)%eilkeyblocksize] < key[current] )
key[(current+addition)%eilkeyblocksize] ^= key[current];
permutebilebox[permutestate++] = key[(current+addition)%eilkeyblocksize];
}
void mix_and_permute_keyblock(unsigned char* key)
{
int i, j=0;
for (i = 0; i < eilkeyblocksize; i++) {
bean_mixa(key, i, j);
bean_mixb(key, i, j);
bean_mix_bilea(key, i, j);
bean_mix_bileb(key, i, j);
j++;
}
}
void mix_and_permute_permuteblock(unsigned char* key)
{
int i;
for (i = 0; i < eilkeyblocksize; i++) {
permutebox[i] += key[i];
}
}
void interate_and_permute_key_into_keybox(unsigned char* key)
{
int i;
for (i = 0; i < eilkeyblocksize; i++) {
key[i%eilkeyblocksize] ^= key[((i+1)%eilkeyblocksize)];
keybox[i] = key[i];
}
}
void put_keystate(u8* key)
{
mix_and_permute_keyblock(key);
mix_and_permute_permuteblock(key);
interate_and_permute_key_into_keybox(key);
}
#define mix_over_boxes(inblock, outblock, blocksize) \
{ int i; int j; \
for (j=0; j < blocksize; j++ ) { \
for ( i = 0; i < eilkeyblocksize; i++) \
{ \
inblock[i] ^= keybox[i]; \
} \
for ( i = 0; i < eilkeyblocksize; i++) \
{ \
inblock[i] ^= permutebox[i]; \
} \
for ( i = 0; i < eilkeyblocksize; i++) \
{ \
inblock[i] ^= original_key_state[i]; \
} \
for ( i = 0; i < eilkeyblocksize; i++) \
{ \
inblock[i] ^= permutebilebox[i]; \
} \
outblock[i] = inblock[i]; \
} \
}
#define unmix_over_boxes(inblock, outblock, blocksize) \
{ int i; int j;\
for (j=0; j < blocksize; j++ ) { \
for ( i = 0; i < eilkeyblocksize; i++) \
{ \
inblock[i] ^= permutebilebox[i]; \
} \
for ( i = 0; i < eilkeyblocksize; i++) \
{ \
inblock[i] ^= original_key_state[i]; \
} \
for ( i = 0; i < eilkeyblocksize; i++) \
{ \
inblock[i] ^= permutebox[i]; \
} \
for ( i = 0; i < eilkeyblocksize; i++) \
{ \
inblock[i] ^= keybox[i]; \
} \
outblock[i] = inblock[i]; \
} \
}
void mix_(u8 *block, u8 *outblock, int blocksize)
{
mix_over_boxes(block, outblock, blocksize)
}
void unmix_(u8 *block, u8 *outblock, int blocksize)
{
unmix_over_boxes(block, outblock, blocksize)
}
void encrypt_block(unsigned char* block, unsigned char* outblock, int blocksize)
{
mix_(block, outblock, blocksize);
}
void decrypt_block(unsigned char* block, unsigned char* outblock, int blocksize)
{
unmix_(block, outblock, blocksize);
}
#include <stdio.h>
#include <string.h>
int main()
{
unsigned char* key;
unsigned char *string = NULL;
char n = 0;
int i = 0;
int j = 0;
key = (unsigned char*) malloc(eilkeyblocksize);
memset(key, 0, eilkeyblocksize);
init_system();
gather_random_fast(key, eilkeyblocksize);
put_keystate(key);
string = (unsigned char*) malloc(1+1);
fprintf(stderr, "enter plaintext[]:");
nullru:
n = getchar();
if ( n == '\n') goto pillmill;
string = (char*) realloc(string, ++j);
string[j-1] = n;
goto nullru;
pillmill:
encrypt_block(string, string, j);
string[j+1] = '\0';
fprintf(stderr, "encrypted: %s\n", string);
decrypt_block(string, string, j);
string[j+1] = '\0';
fprintf(stderr, "decrypted: %s\n", string);
close_system();
return 0;
}
------------------------------------------------------------------------------------------------------------------------
#define eilblocksize 32
#define eilkeyblocksize 32
#define u8 unsigned char
unsigned char* key;
unsigned char original_key_state[eilkeyblocksize];
void bean_mixa(unsigned char *key, int current, int addition)
{
if ( key[current] > key[current+addition] )
key[current] ^= key[current+addition];
}
void bean_mixb(unsigned char *key, int current, int addition)
{
if ( key[current] < key[current+addition] )
key[current+addition] ^= key[current];
}
void bean_mixc(unsigned char *key, int current, int addition)
{
if ( key[current+addition] < key[current] )
key[current+addition] ^= key[current];
}
void bean_mixd(unsigned char *key, int current, int addition)
{
if ( key[current+addition] > key[current] )
key[current+addition] ^= key[current];
}
void mix_and_permute_keyblock(unsigned char* key)
{
int i, j=0;
for (i = 0; i < eilkeyblocksize; i++)
original_key_state[i] = key[i];
for (i = 0; i < eilkeyblocksize; i++) {
bean_mixa(key, i, j+1%eilkeyblocksize);
bean_mixb(key, i, j+1%eilkeyblocksize);
bean_mixc(key, i, j+1%eilkeyblocksize);
bean_mixd(key, i, j+1%eilkeyblocksize);
j++;
}
j=0;
for (i = 0; i < eilkeyblocksize; i++) {
bean_mixa(key, i, j+1%eilkeyblocksize);
bean_mixb(key, i, j+1%eilkeyblocksize);
bean_mixc(key, i, j+1%eilkeyblocksize);
bean_mixd(key, i, j+1%eilkeyblocksize);
j++;
}
}
void put_keystate(u8* key)
{
mix_and_permute_keyblock(key);
}
#define mix_over_boxes(inblock, outblock, blocksize) \
{ int j; unsigned char n; \
for (j=0; j < blocksize; j++ ) { \
n = inblock[j]; \
{ int i; for(i=0;i<eilkeyblocksize;i++) { \
n ^= original_key_state[i]; \
n ^= key[i]; \
} \
} \
outblock[j] = n; \
} \
}
#define unmix_over_boxes(inblock, outblock, blocksize) \
{ int j; unsigned char n; \
for (j=0; j < blocksize; j++ ) { \
n = inblock[j]; \
{ int i; for(i=0;i<eilkeyblocksize;i++) { \
n ^= key[i]; \
n ^= original_key_state[i]; \
} \
} \
outblock[j] = n; \
} \
}
void mix_(u8 *block, u8 *outblock, int blocksize)
{
mix_over_boxes(block, outblock, blocksize)
}
void unmix_(u8 *block, u8 *outblock, int blocksize)
{
unmix_over_boxes(block, outblock, blocksize)
}
void encrypt_block(unsigned char* block, unsigned char* outblock, int blocksize)
{
mix_(block, outblock, blocksize);
}
void decrypt_block(unsigned char* block, unsigned char* outblock, int blocksize)
{
unmix_(block, outblock, blocksize);
}
#include <stdio.h>
#include <string.h>
int main()
{
unsigned char *string = NULL;
unsigned char *out = NULL;
unsigned char *out_ = NULL;
char n = 0;
int j = 0;
key = (unsigned char*) malloc(eilkeyblocksize);
memset(key, 0, eilkeyblocksize);
init_system();
gather_random_fast(key, eilkeyblocksize);
put_keystate(key);
string = (unsigned char*) malloc(1);
fprintf(stderr, "enter plaintext[]:");
nullru:
n = getchar();
if ( n == '\n') goto pillmill;
string = (char*) realloc(string, ++j);
string[j-1] = n;
goto nullru;
pillmill:
if ( !out )
out = (unsigned char*) malloc(j);
else
out = (unsigned char*) realloc(out, j);
encrypt_block(string, out, j);
if ( !out_ )
out_ = (unsigned char*) malloc(j);
else
out_ = (unsigned char*) realloc(out_, j);
{ int i; fprintf(stderr, "plaintext values in decimals: "); for(i=0; i < strlen(string); i++) fprintf(stderr, "%d ", string[i]); }
fprintf(stderr, "\nencrypted: encrypted values in decimals: ");
{ int i; for(i=0; i < strlen(string); i++) fprintf(stderr, "%d ", out[i]); }
decrypt_block(out, out_, j);
fprintf(stderr, "\ndecrypted: decrypted values in decimals: ");
{ int i; for(i=0; i < strlen(string); i++) fprintf(stderr, "%d ", out_[i]); }
return 0;
}
Thursday, September 14, 2017
eil key permutation cipher transformation code: 'signing' eil conditioning opeind preodd state :: static amit order 1 :: awon (one) :: sources opind aowon aoloe (two)
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment