exploit the possibilities
Home Files News &[SERVICES_TAB]About Contact Add New

vce.c

vce.c
Posted Dec 14, 2005
Authored by Dylan Fleming

C89 implementation of the Vignere cipher compiled and tested on Windows XP, Windows 2000 and FreeBSD 4.11

tags | encryption
systems | windows, freebsd
SHA-256 | dfc16eba9f66d1a3bb503120747fe225fc107f0b593f0856ba0845880c5c0eb9

vce.c

Change Mirror Download
/*
Vignere Console Encryptor [VCE]
Coded by Dylan Fleming [flemingd@gmail.com]
05DEC05

This program will take data from a file or data stream
and encrypt it using the Vignere cipher. This was a
requested program on www.rentacoder.com and was completed
to fill the request. Dylan Fleming retains all rights
to this program and the source code contained therein.
Unauthorized use of this code or the program may result
in a lawsuit. Please contact Dylan Fleming via e-mail
if you have any question about this programming or wish
to use the source code or application for yourself.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/* show help information about this program */
void show_usage()
{
printf("Vignere Console Encryptor [VCE]\n");
printf("Coded by Dylan Fleming [flemingd@gmail.com]\n");
printf("Usage:\n"
"vce [fotked] [arguments ...]\n"
"Variables are passed in tar-style format.\n"
" h or --help\tShow this message.\n"
" f\t\tName of file to read data from.\n"
" o\t\tName of file to output data to.\n"
" t\t\tRead data from stdin.\n"
" k\t\tKey to be used to process data.\n"
" e\t\tEncrypt the input data.\n"
" d\t\tDecrypt the input data.\n"
);
printf("Examples:\n"
" vce toke cipher_text.txt KEYSTRINGabc123\n"
" vce dfok cipher_text.txt plain_text.txt KEYSTRINGabc123\n"
);
exit(1);
}

/*
encrypts data aquired from string and places it in output file
variables:
stream [char array] - input data
count [integer] - length of input data
ofile [FILE handle] - output file
keystring [char array] - key for encryption
addkey [toggle option] - 1 = add key, 0 = subtract key
*/
int cipher(unsigned char *stream, FILE *ofile, unsigned char *keystring, unsigned char addkey)
{
unsigned long n, j;
unsigned long len, slen;
unsigned char c;

/* setup cipher for processing */
len = strlen(keystring);
slen = strlen(stream);

/* begin cipher itterations */
for ( n = 0, j= 0; n < slen; n++ )
{
c = stream[n];

if ( addkey ) c += keystring[j];
else c -= keystring[j];

j = ( j++ ) % len;
fputc(c, ofile);
}

/* cleanup and return */
fclose(ofile);
return 1;
}

/*
encrypts data aquired from input file and places it in output file
variables:
hfile [FILE handle] - input file
ofile [FILE handle] - output file
keystring [char array] - key for encryption
addkey [toggle option] - 1 = add key, 0 = subtract key
*/
int fcipher(FILE *hfile, FILE *ofile, unsigned char *keystring, unsigned char addkey)
{
unsigned long n = 0, j = 0;
unsigned long len;
unsigned char c;

/* setup cipher for processing */
len = strlen(keystring);

/* begin cipher itterations */
while (1)
{
c = fgetc(hfile);
if ( feof(hfile) ) break;

if ( addkey ) c += keystring[j];
else c -= keystring[j];

j = ( j++ ) % len;
fputc(c, ofile);
}

/* cleanup and return */
fclose(ofile);
fclose(hfile);
return 1;
}

/* main entry point for program */
int main(int argc, char *argv[])
{
unsigned char addkey = 0;
unsigned char f, n, a, c;
unsigned short len;
unsigned char iname[1024], oname[1024], keyring[1024], sdata[4096];
FILE *ifile, *ofile;

/* initialize string data variables */
memset(oname, 0, sizeof(oname));
memset(iname, 0, sizeof(iname));
memset(keyring, 0, sizeof(keyring));

/* process arguments for program */
if ( argc < 2 ) show_usage();
if ( !strcmp(argv[1], "--help") || !strcmp(argv[0], "/?") ) show_usage();
len = strlen(argv[1]);
for ( f = 1, n = 0, a = 2, c = 0; c < len; c++ )
{
n = argv[1][c];
if ( n == 'h' ) show_usage(); /* show help */
else if ( n == 'f' ) { strcpy(iname, argv[a]); a++; } /* read input from file */
else if ( n == 'e' ) { addkey = 1; } /* add keystring to data */
else if ( n == 'd' ) { addkey = 0; } /* subtract keystring from data */
else if ( n == 't' ) { f = 0; } /* read input from stdin */
else if ( n == 'o' ) { strcpy(oname, argv[a]); a++; } /* set output file name */
else if ( n == 'k' ) { strcpy(keyring, argv[a]); a++; } /* set key */
else if ( n == '-' ) { a++; a--; } /* do nothing */
else { printf("Unknown option \"%c\", ignored.\n", n); } /* throw error for invalid options */
}

/* check buffers for proper data */
if ( !strlen(oname) ) show_usage();
if ( f && !strlen(iname) ) show_usage();
if ( !strlen(keyring) ) show_usage();
if ( (ofile = fopen(oname, "wb")) == NULL )
{
printf("Invalid output file name or file creation failed.\n");
return 1;
}
if ( f && ((ifile = fopen(iname, "rb")) == NULL) )
{
printf("Invalid input file name or file not found.\n");
return 1;
}

/* process input file */
if ( f )
{
if ( !fcipher(ifile, ofile, keyring, addkey) ) {
printf("Processing of file \"%s\" failed.\n", iname);
return 1;
}
printf("File \"%s\" finished processing successfully.\n", iname);
return 0;
}
/* process typed data */
else
{
memset(sdata, 0, sizeof(sdata));
printf("Please start your writing your message to be encryted now. [Max. 4000 characters]\n\n");
if ( fgets(sdata, 4000, stdin) == NULL ) {
printf("Error reading data for encryption.\n");
return 1;
}

if ( !cipher(sdata, ofile, keyring, addkey) ) {
printf("Processing of typed data failed.\n");
return 1;
}
printf("Typed data finished processing successfully.\n");
return 0;
}

return 0;
}
Login or Register to add favorites

File Archive:

August 2024

  • Su
  • Mo
  • Tu
  • We
  • Th
  • Fr
  • Sa
  • 1
    Aug 1st
    15 Files
  • 2
    Aug 2nd
    22 Files
  • 3
    Aug 3rd
    0 Files
  • 4
    Aug 4th
    0 Files
  • 5
    Aug 5th
    15 Files
  • 6
    Aug 6th
    11 Files
  • 7
    Aug 7th
    43 Files
  • 8
    Aug 8th
    42 Files
  • 9
    Aug 9th
    36 Files
  • 10
    Aug 10th
    0 Files
  • 11
    Aug 11th
    0 Files
  • 12
    Aug 12th
    27 Files
  • 13
    Aug 13th
    18 Files
  • 14
    Aug 14th
    50 Files
  • 15
    Aug 15th
    33 Files
  • 16
    Aug 16th
    23 Files
  • 17
    Aug 17th
    0 Files
  • 18
    Aug 18th
    0 Files
  • 19
    Aug 19th
    43 Files
  • 20
    Aug 20th
    0 Files
  • 21
    Aug 21st
    0 Files
  • 22
    Aug 22nd
    0 Files
  • 23
    Aug 23rd
    0 Files
  • 24
    Aug 24th
    0 Files
  • 25
    Aug 25th
    0 Files
  • 26
    Aug 26th
    0 Files
  • 27
    Aug 27th
    0 Files
  • 28
    Aug 28th
    0 Files
  • 29
    Aug 29th
    0 Files
  • 30
    Aug 30th
    0 Files
  • 31
    Aug 31st
    0 Files

Top Authors In Last 30 Days

File Tags

Systems

packet storm

© 2022 Packet Storm. All rights reserved.

Services
Security Services
Hosting By
Rokasec
close