Suntuubi-palvelussa käytetään evästeitä. Palvelua käyttämällä hyväksyt evästeiden käytön. Lue lisää. OK

// Numencrypt by LJ 0.5 beta

/* Numencrypt By LJ on LJ:n tekemä ei ihan niin simppeli ohjelma. Ohjelma

kysyy käyttäjältä lukua salattavaksi. Ohjelma salaa luvun

käyttämällä laskutoimituksia,  joiden tulokset riippuvat joko

käyttäjän valitsemista tai järjestelmäkelloon perustuen arvotuista

siemenistä. Sen jälkeen käyttäjä voi vielä tallettaa luvun ja/tai siemenet tiedostoon */

#include <stdio.h>  /* include the libraries */
#include <stdlib.h>
#include <time.h>
#include <conio.h>
/* variables to be used in the hole program. ---------------------------------------------------------------*/
long int number = 0;
short int seeds = 0;
char rd = ' ';
char fname[150];
long int x = 0;
long int y = 0;
long int z = 0;
long int a = 0;
long int b = 0;
long int c = 0;
long int d = 0;
long int e = 0;
long int f = 0;
long int g = 0;
long int xy = 0;
long int yx = 0;
long int ab = 0;
long int xz = 0;
long int yy = 0;
long int zx = 0;
long int zy = 0;
/* functions begin --------------------------------------------------------------------------------------*/
int decide (void)  {
printf("Please dont give seeds over 800 000 000 00!\n");
switch (seeds) {
       case 1:
            printf("Gimme seed x!\n");
            scanf("%d", &x);
             break;
       case 2:
            printf("Gimme seed x!\n");
            scanf("%d", &x);
            printf("Gimme seed y!\n");
            scanf("%d", &y);
            break;
       case 3:
            printf("Gimme seed x!\n");
            scanf("%d", &x);
            printf("Gimme seed y!\n");
            scanf("%d", &y);
            printf("Gimme seed z!\n");
            scanf("%d", &z);
            break;
       case 4:
            printf("Gimme seed x!\n");
            scanf("%d", &x);
            printf("Gimme seed y!\n");
            scanf("%d", &y);
            printf("Gimme seed z!\n");
            scanf("%d", &z);
            printf("Gimme seed a!\n");
            scanf("%d", &a);
            break;
       case 5:
            printf("Gimme seed x!\n");
            scanf("%d", &x);
            printf("Gimme seed y!\n");
            scanf("%d", &y);
            printf("Gimme seed z!\n");
            scanf("%d", &z);
            printf("Gimme seed a!\n");
            scanf("%d", &a);
            printf("Gimme seed b!\n");
            scanf("%d", &b);
            break;
       case 6:
            printf("Gimme seed x!\n");
            scanf("%d", &x);
            printf("Gimme seed y!\n");
            scanf("%d", &y);
            printf("Gimme seed z!\n");
            scanf("%d", &z);
            printf("Gimme seed a!\n");
            scanf("%d", &a);
            printf("Gimme seed b!\n");
            scanf("%d", &b);
            printf("Gimme seed c!\n");
            scanf("%d", &c);
            break;
       case 7:
            printf("Gimme seed x!\n");
            scanf("%d", &x);
            printf("Gimme seed y!\n");
            scanf("%d", &y);
            printf("Gimme seed z!\n");
            scanf("%d", &z);
            printf("Gimme seed a!\n");
            scanf("%d", &a);
            printf("Gimme seed b!\n");
            scanf("%d", &b);
            printf("Gimme seed c!\n");
            scanf("%d", &c);
            printf("Gimme seed d!\n");
            scanf("%d", &d);
            break;
       case 8:
            printf("Gimme seed x!\n");
            scanf("%d", &x);
            printf("Gimme seed y!\n");
            scanf("%d", &y);
            printf("Gimme seed z!\n");
            scanf("%d", &z);
            printf("Gimme seed a!\n");
            scanf("%d", &a);
            printf("Gimme seed b!\n");
            scanf("%d", &b);
            printf("Gimme seed c!\n");
            scanf("%d", &c);
            printf("Gimme seed d!\n");
            scanf("%d", &d);
            printf("Gimme seed e!\n");
            scanf("%d", &e);
            break;
       case 9:
            printf("Gimme seed x!\n");
            scanf("%d", &x);
            printf("Gimme seed y!\n");
            scanf("%d", &y);
            printf("Gimme seed z!\n");
            scanf("%d", &z);
            printf("Gimme seed a!\n");
            scanf("%d", &a);
            printf("Gimme seed b!\n");
            scanf("%d", &b);
            printf("Gimme seed c!\n");
            scanf("%d", &c);
            printf("Gimme seed d!\n");
            scanf("%d", &d);
            printf("Gimme seed e!\n");
            scanf("%d", &e);
            printf("Gimme seed f!\n");
            scanf("%d", &f);
            break;
       case 10:
            printf("Gimme seed x!\n");
            scanf("%d", &x);
            printf("Gimme seed y!\n");
            scanf("%d", &y);
            printf("Gimme seed z!\n");
            scanf("%d", &z);
            printf("Gimme seed a!\n");
            scanf("%d", &a);
            printf("Gimme seed b!\n");
            scanf("%d", &b);
            printf("Gimme seed c!\n");
            scanf("%d", &c);
            printf("Gimme seed d!\n");
            scanf("%d", &d);
            printf("Gimme seed e!\n");
            scanf("%d", &e);
            printf("Gimme seed f!\n");
            scanf("%d", &f);
            printf("Gimme seed g!\n");
            scanf("%d", &g);
            break;
       default:
               printf("incorrect value, exiting!");
               return 0;
}
}
/* function changes --------------------------------------------------------------------------------------*/
void save (void) {
     FILE *fp;
     printf("Where do you want to save the encrypted number? (file path), doesnt need to exist\n");
     scanf ("%s", &fname);
     if ( (fp = fopen( fname, "a" ) ) != NULL) {
          fprintf( fp, "%d", number);
}
else {
     printf("Error while prosessing the file!\n");
}
fclose (fp);
}
/* function changes --------------------------------------------------------------------------------------*/
void caseten (void) {
FILE *fp;
if ( (fp = fopen( fname, "a" ) ) != NULL) {
     fprintf(fp, "x = ");
     fprintf( fp, "%d\n", x);
     fprintf(fp, "y = ");
     fprintf( fp, "%d\n", y);
     fprintf(fp, "z = ");
     fprintf( fp, "%d\n", z);
     fprintf(fp, "a = ");
     fprintf( fp, "%d\n", a);
     fprintf(fp, "b = ");
     fprintf( fp, "%d\n", b);
     fprintf(fp, "c = ");
     fprintf( fp, "%d\n", c);
     fprintf(fp, "d = ");
     fprintf( fp, "%d\n", d);
     fprintf(fp, "e = ");
     fprintf( fp, "%d\n", e);
     fprintf(fp, "f = ");
     fprintf( fp, "%d\n", f);
     fprintf(fp, "g = ");
     fprintf( fp, "%d\n", g);
}
else {
     printf("Error while prosessing the file!\n");
}
fclose (fp);
}
/* function changes --------------------------------------------------------------------------------------*/
void casenine (void) {
FILE *fp;
if ( (fp = fopen( fname, "a" ) ) != NULL) {
     fprintf(fp, "x = ");
     fprintf( fp, "%d\n", x);
     fprintf(fp, "y = ");
     fprintf( fp, "%d\n", y);
     fprintf(fp, "z = ");
     fprintf( fp, "%d\n", z);
     fprintf(fp, "a = ");
     fprintf( fp, "%d\n", a);
     fprintf(fp, "b = ");
     fprintf( fp, "%d\n", b);
     fprintf(fp, "c = ");
     fprintf( fp, "%d\n", c);
     fprintf(fp, "d = ");
     fprintf( fp, "%d\n", d);
     fprintf(fp, "e = ");
     fprintf( fp, "%d\n", e);
     fprintf(fp, "f = ");
     fprintf( fp, "%d\n", f);
}
else {
     printf("Error while prosessing the file!\n");
}
fclose (fp);
}
/* function changes --------------------------------------------------------------------------------------*/
void caseeight (void) {
FILE *fp;
if ( (fp = fopen( fname, "a" ) ) != NULL) {
     fprintf(fp, "x = ");
     fprintf( fp, "%d\n", x);
     fprintf(fp, "y = ");
     fprintf( fp, "%d\n", y);
     fprintf(fp, "z = ");
     fprintf( fp, "%d\n", z);
     fprintf(fp, "a = ");
     fprintf( fp, "%d\n", a);
     fprintf(fp, "b = ");
     fprintf( fp, "%d\n", b);
     fprintf(fp, "c = ");
     fprintf( fp, "%d\n", c);
     fprintf(fp, "d = ");
     fprintf( fp, "%d\n", d);
     fprintf(fp, "e = ");
     fprintf( fp, "%d\n", e);
}
else {
     printf("Error while prosessing the file!\n");
}
fclose (fp);
}
/* function changes --------------------------------------------------------------------------------------*/
void caseseven (void) {
FILE *fp;
if ( (fp = fopen( fname, "a" ) ) != NULL) {
     fprintf(fp, "x = ");
     fprintf( fp, "%d\n", x);
     fprintf(fp, "y = ");
     fprintf( fp, "%d\n", y);
     fprintf(fp, "z = ");
     fprintf( fp, "%d\n", z);
     fprintf(fp, "a = ");
     fprintf( fp, "%d\n", a);
     fprintf(fp, "b = ");
     fprintf( fp, "%d\n", b);
     fprintf(fp, "c = ");
     fprintf( fp, "%d\n", c);
     fprintf(fp, "d = ");
     fprintf( fp, "%d\n", d);
}
else {
     printf("Error while prosessing the file!\n");
}
fclose (fp);
}
/* function changes --------------------------------------------------------------------------------------*/
void casesix (void) {
FILE *fp;
if ( (fp = fopen( fname, "a" ) ) != NULL) {
     fprintf(fp, "x = ");
     fprintf( fp, "%d\n", x);
     fprintf(fp, "y = ");
     fprintf( fp, "%d\n", y);
     fprintf(fp, "z = ");
     fprintf( fp, "%d\n", z);
     fprintf(fp, "a = ");
     fprintf( fp, "%d\n", a);
     fprintf(fp, "b = ");
     fprintf( fp, "%d\n", b);
     fprintf(fp, "c = ");
     fprintf( fp, "%d\n", c);
}
else {
     printf("Error while prosessing the file!\n");
}
fclose (fp);
}
/* function changes --------------------------------------------------------------------------------------*/
void casefive (void) {
FILE *fp;
if ( (fp = fopen( fname, "a" ) ) != NULL) {
     fprintf(fp, "x = ");
     fprintf( fp, "%d\n", x);
     fprintf(fp, "y = ");
     fprintf( fp, "%d\n", y);
     fprintf(fp, "z = ");
     fprintf( fp, "%d\n", z);
     fprintf(fp, "a = ");
     fprintf( fp, "%d\n", a);
     fprintf(fp, "b = ");
     fprintf( fp, "%d\n", b);
}
else {
     printf("Error while prosessing the file!\n");
}
fclose (fp);
}
/* function changes --------------------------------------------------------------------------------------*/
void casefour (void) {
FILE *fp;
if ( (fp = fopen( fname, "a" ) ) != NULL) {
     fprintf(fp, "x = ");
     fprintf( fp, "%d\n", x);
     fprintf(fp, "y = ");
     fprintf( fp, "%d\n", y);
     fprintf(fp, "z = ");
     fprintf( fp, "%d\n", z);
     fprintf(fp, "a = ");
     fprintf( fp, "%d\n", a);
}
else {
     printf("Error while prosessing the file!\n");
}
fclose (fp);
}
/* function changes --------------------------------------------------------------------------------------*/
void casethree (void) {
FILE *fp;
if ( (fp = fopen( fname, "a" ) ) != NULL) {
     fprintf(fp, "x = ");
     fprintf( fp, "%d\n", x);
     fprintf(fp, "y = ");
     fprintf( fp, "%d\n", y);
     fprintf(fp, "z = ");
     fprintf( fp, "%d\n", z);
}
else {
     printf("Error while prosessing the file!\n");
}
fclose (fp);
}
/* function changes --------------------------------------------------------------------------------------*/
void casetwo (void) {
FILE *fp;
if ( (fp = fopen( fname, "a" ) ) != NULL) {
     fprintf(fp, "x = ");
     fprintf( fp, "%d\n", x);
     fprintf(fp, "y = ");
     fprintf( fp, "%d\n", y);
}
else {
     printf("Error while prosessing the file!\n");
}
fclose (fp);
}
/* function changes --------------------------------------------------------------------------------------*/
void caseone (void) {
FILE *fp;
if ( (fp = fopen( fname, "a" ) ) != NULL) {
     fprintf(fp, "x = ");
     fprintf( fp, "%d\n", x);
}
else {
     printf("Error while prosessing the file!\n");
}
fclose (fp);
}
/* function changes --------------------------------------------------------------------------------------*/
void saveseeds (void) {
     printf("Where do you want to save the encryption seeds? (file path), doesnt need to exist.\n");
     scanf ("%s", &fname);
     switch (seeds) {
            case 1:
                 caseone();
                 break;
            case 2:
                 casetwo();
                 break;
            case 3:
                 casethree();
                 break;
            case 4:
                 casefour();
                 break;
            case 5:
                 casefive();
                 break;
            case 6:
                 casesix();
                 break;
            case 7:
                 caseseven();
                 break;
            case 8:
                 caseeight();
                 break;
            case 9:
                 casenine();
                 break;
            case 10:
                 caseten();
                 break;
}
}
/* main, program begins --------------------------------------------------------------------------------------*/
int main (void) {
srand((unsigned)time(0));
printf("How many seeds do you want to use?, 1 - 10\n");
scanf("%d", &seeds);
printf("Do you want to decide seeds yourself or use randomized seeds? D to decide.\n");
rd = getch();
switch (rd) {
       default:
               x = (int) (rand()% 800000000 + 1);
               y = (int) (rand()% 800000000 + 1);
               z = (int) (rand()% 800000000 + 1);
               a = (int) (rand()% 800000000 + 1);
               b = (int) (rand()% 800000000 + 1);
               c = (int) (rand()% 800000000 + 1);
               d = (int) (rand()% 800000000 + 1);
               e = (int) (rand()% 800000000 + 1);
               f = (int) (rand()% 800000000 + 1);
               g = (int) (rand()% 800000000 + 1);
               break;
       case 'D': case 'd':
            decide();
            break;
}           
printf("gimme the number to encrypt!\nMax 2,147,483,647, min -2,147,483,648\n");
scanf("%d", &number);
switch (seeds) {
       case 1:
            number = (number - x);
            number = (number + 891);
            number = (number + x);
            number = (number - 94573);
            number = (number + x);
            number = (number + 37532);
            number = (number + x);
            printf("Encryption seed (x) was ");
            printf("%d", x);
            break;
       case 2:
            xy = (x + y);
            xy = (xy - 154);
            number = (number + xy);
            number = (number + y);
            number = (number - x);
            number = (number + 894356);
            number = (number + y);
            number = (number - 986);
            printf("Encryption seed x was ");
            printf("%d", x);
            printf("\nEncryption seed y was ");
            printf("%d", y);
            break;
       case 3:
            number = (number - z);
            number = (number + y);
            number = (number + 186);
            xz = (x + z);
            number = (number - xz);
            number = (number + y);
            number = (number + 17659);
            printf("Encryption seed x was ");
            printf("%d", x);
            printf("\nEncryption seed y was ");
            printf("%d", y);
            printf("\nEncryption seed z was ");
            printf("%d", z);
            break;
       case 4:
            yx = (x - y);
            number = (number - yx);
            number = (number - a);
            number = (number + z);
            number = (number + z);
            number = (number + x);
            number = (number - 89543);
            printf("Encryption seed x was ");
            printf("%d", x);
            printf("\nEncryption seed y was ");
            printf("%d", y);
            printf("\nEncryption seed z was ");
            printf("%d", z);
            printf("\nEncryption seed a was ");
            printf("%d", a);
            break;
       case 5:
            yy = (y * 2);
            zx = (z - x);
            number = (number - yy);
            number = (number + zx);
            number = (number + a);
            number = (number - b);
            number = (number + 896543);
            number = (number + 1);
            printf("Encryption seed x was ");
            printf("%d", x);
            printf("\nEncryption seed y was ");
            printf("%d", y);
            printf("\nEncryption seed z was ");
            printf("%d", z);
            printf("\nEncryption seed a was ");
            printf("%d", a);
            printf("\nEncryption seed b was ");
            printf("%d", b);
            break;
       case 6:
            number = (number + y);
            number = (number - a);
            number = (number - b);
            number = (number + y);
            number = (number - x);
            number = (number - b);
            number = (number + c);
            number = (number - z);
            number = (number + c);
            number = (number + y);
            number = (number - y);
            printf("Encryption seed x was ");
            printf("%d", x);
            printf("\nEncryption seed y was ");
            printf("%d", y);
            printf("\nEncryption seed z was ");
            printf("%d", z);
            printf("\nEncryption seed a was ");
            printf("%d", a);
            printf("\nEncryption seed b was ");
            printf("%d", b);
            printf("\nEncryption seed c was ");
            printf("%d", c);
            break;
       case 7:
            number = (number - x);
            number = (number + y);
            zy = (z + y);
            number = (number - zy);
            number = (number - a);
            number = (number + c);
            number = (number + d);
            number = (number + 134);
            number = (number - b);
            printf("Encryption seed x was ");
            printf("%d", x);
            printf("\nEncryption seed y was ");
            printf("%d", y);
            printf("\nEncryption seed z was ");
            printf("%d", z);
            printf("\nEncryption seed a was ");
            printf("%d", a);
            printf("\nEncryption seed b was ");
            printf("%d", b);
            printf("\nEncryption seed c was ");
            printf("%d", c);
            printf("\nEncryption seed d was ");
            printf("%d", d);
            break;
       case 8:
            number = (number + e);
            number = (number + a);
            number = (number - z);
            number = (number + 6529);
            number = (number - 1);
            number = (number - d);
            number = (number + b);
            number = (number + c);
            number = (number - x);
            number = (number - y);
            printf("Encryption seed x was ");
            printf("%d", x);
            printf("\nEncryption seed y was ");
            printf("%d", y);
            printf("\nEncryption seed z was ");
            printf("%d", z);
            printf("\nEncryption seed a was ");
            printf("%d", a);
            printf("\nEncryption seed b was ");
            printf("%d", b);
            printf("\nEncryption seed c was ");
            printf("%d", c);
            printf("\nEncryption seed d was ");
            printf("%d", d);
            printf("\nEncryption seed e was ");
            printf("%d", e);
            break;
       case 9:
            xy = (x - y);
            ab = (a + b);
            number = (number + xy);
            number = (number - ab);
            number = (number + 785221);
            number = (number - z);
            number = (number + c);
            number = (number - d);
            number = (number + e);
            number = (number + f);
            printf("Encryption seed x was ");
            printf("%d", x);
            printf("\nEncryption seed y was ");
            printf("%d", y);
            printf("\nEncryption seed z was ");
            printf("%d", z);
            printf("\nEncryption seed a was ");
            printf("%d", a);
            printf("\nEncryption seed b was ");
            printf("%d", b);
            printf("\nEncryption seed c was ");
            printf("%d", c);
            printf("\nEncryption seed d was ");
            printf("%d", d);
            printf("\nEncryption seed e was ");
            printf("%d", e);
            printf("\nEncryption seed f was ");
            printf("%d", f);
            break;
       case 10:
            xy = (y - x);
            ab = (a - b);
            number = (number - xy);
            number = (number - xy);
            number = (number + 15973);
            number = (number - z);
            number = (number + d);
            number = (number + c);
            number = (number - e);
            number = (number - 1);
            number = (number + f);
            number = (number - g);
            number = (number - 143);
            printf("Encryption seed x was ");
            printf("%d", x);
            printf("\nEncryption seed y was ");
            printf("%d", y);
            printf("\nEncryption seed z was ");
            printf("%d", z);
            printf("\nEncryption seed a was ");
            printf("%d", a);
            printf("\nEncryption seed b was ");
            printf("%d", b);
            printf("\nEncryption seed c was ");
            printf("%d", c);
            printf("\nEncryption seed d was ");
            printf("%d", d);
            printf("\nEncryption seed e was ");
            printf("%d", e);
            printf("\nEncryption seed f was ");
            printf("%d", f);
            printf("\nEncryption seed g was ");
            printf("%d", g);
            break;
       default:
               printf("Incorrect value, exiting!\n");
               return 0;
               break;
}           
printf("\nThe encrypted number is ");
printf("%d\n", number);
printf("Do you want to save encrypted number in a file? S to save\n");
rd = getch();
switch (rd) {
       case 'S': case 's':
            save();
            break;
       default:
               break;
}
printf("Do you want to save the encryption seeds in a file? S to save\n");
rd = getch();
switch (rd) {
       case 'S': case 's':
            saveseeds();
            break;
       default:
               break;
}
printf("Use numdecrypt.exe to decrypt the number.");
return 0;
}


©2017 Ohjelmointi ja modaussivut - suntuubi.com