// aug5ex2.cpp : Defines the entry point for the console application.
//  Scramble Alphabet, then encrypt a message!

#include "stdafx.h"
#include "stdlib.h"
#include "time.h"

int main(int argc, char* argv[])
{   int encrypt [26] = {0};
    int letter, pos;

	srand(time(NULL));

// scramble the alphabet! - Finds a position for each letter that is still empty (i.e. still 0)
	
	for (letter='A'; letter <= 'Z'; letter++) {

		do {
               pos = rand() % 26;
             
		} while  (encrypt[pos] != 0);  /*keep picking a pos while you haven't found a blank one */

		encrypt[pos] = letter;

	} /* end for letter */

	printf("\nHere is the scrambled alphabet:\n");

	for (letter='A'; letter<='Z'; letter++)
		 printf("%c", letter);
	printf("\n");

	for (pos=0; pos<26; pos++)
		printf("%c", encrypt[pos]);
	printf("\n");

	printf("Now type your secret message so I can enclode it!\n");

	while( (letter = getchar() ) != EOF) {

         if ( (letter >= 'a') && (letter <= 'z') )
			 letter = letter - ('a' - 'A');

         if ( (letter >= 'A') && (letter <= 'Z') )
			 printf ("%c", encrypt[ letter  - 'A' ] );
		   else
			 printf("%c", letter);

	} /* end while letter */

	printf("\n");

	return 0;
}