All pastes #1913439 Raw Edit

Vigenere.c

public c v1 · immutable
#1913439 ·published 2010-08-08 20:10 UTC
rendered paste body
/****************************************************************************** vigenere.c** Robert Skinner** Encrypts messages by using Vigenere's cipher.*****************************************************************************/#include <stdio.h>#include <ctype.h>#include <stdlib.h>#include <string.h>intmain(int argc, char *argv[]){    int keySpotPreserver = 0;    char* key, keyStrLen, strLen;    char inputString[255], outputString[255];    if(argv[1] != NULL)	key = argv[1];    else{	printf("You need to enter a key word in the command line.\n");	return 1;    }    keyStrLen = strlen(argv[1]);    printf("%d", keyStrLen);    for(int i = 0; i < keyStrLen; i++)	if(isdigit(argv[1][i]) != 0){	    printf("All or part of your key contains numbers, please use ");	    printf("letters only.\n");	    return 2;	}    printf("Enter the statement you want to encode(255 characters or less): ");    fgets(inputString, 255, stdin);    strLen = strlen(inputString) - 2;    for(int j = 0; j <= strLen; j++){	if(inputString[j] < 'A' || (inputString[j] > 'Z' &&	inputString[j] < 'a') || inputString[j] > 'z'){	    outputString[j] = inputString[j];	    keySpotPreserver--;	    printf("%d", keySpotPreserver);	} else	    if(inputString[j] >= 'A' && inputString[j] <= 'Z')		outputString[j] = (((inputString[j] - 'A') +		(key[(j - keySpotPreserver) % keyStrLen] - 'A')) % 26) + 'A';	    else		if(inputString[j] >= 'a' && inputString[j] <= 'z')		    outputString[j] = (((inputString[j] - 'a') +		    (key[(j - keySpotPreserver) % keyStrLen] - 'a')) % 26) + 'a';    }    printf("%s\n", outputString);    return 0;}