Esempio n. 1
0
/*--------------------------------------------------------------------------------------------------------------
 * FUNCTION: ControllerEncryptDecrypt
 * DESCR:    Encrypts the plaintext to produce the ciphertext or decrypts the ciphertext to produce the plain-
 *           text. The message is read from stdin by calling ViewGetStr().
 * RETURNS:  If pMode is VIGENERE_ENCRYPT, pMsgOut is the ciphertext. If pMode is VIGENERE_DECRYPT, pMstOut is
 *           the plaintext.
 *------------------------------------------------------------------------------------------------------------*/
static void ControllerEncryptDecrypt(bool  pMode,char *pMsgOut)
{
    /* Define a character array named msgIn which has room for MAX_MSG_LEN+1 characters. */
    char *msgIn[MAX_MSG_LEN+1];

    /* Call ViewGetStr() to get the message string to be encrypted or decrypted. */
	ViewGetStr(*msgIn);

    /* Call Vigenere() to encrypt or decrypt the message. */
    Vigenere(pMode,ModelGetKey(),*msgIn,pMsgOut);
}
int
main(int argc, char *argv[])
{
    if (!VerifyArgs(argc, argv)){
        printf("Sumfink bad happen.\n");
        return 1;
    }
    
    string plainText;
    do{
        printf("String to encrypt: ");
        plainText = GetString();
    }
    while (strlen(plainText) <= 0);
    
    printf("%s\n", plainText);
    Vigenere(argv[1], plainText);
    return 0;
}