It looks like you're using an Ad Blocker.
Please white-list or disable AboveTopSecret.com in your ad-blocking tool.
Thank you.
Some features of ATS will be disabled while you continue to use an ad-blocker.
#include
#include
/*encode function, to encode user input */
int main()
[
char buff[BUFSIZ];
int i = 0;
int shift_value;
int p = 0;
printf( "**initializing.....**\n\n"
"**linking..........**\n\n");
printf( "Welcome agent Brown\n\n");
printf( "You have accessed the Caesar Cipher program\n\n");
printf("\nPlease enter the text you wish to encrypt: ");/*accept user input */
fgets(buff, sizeof(buff), stdin);
printf("\nEnter your encryption shift value (anything from +-1 to 25): ");
scanf ("%i", &shift_value);
[
while ( buff != '\0' )
[
buff = buff + shift_value + i++;
]
]
printf("\n Your encrypted text is:%s\n",buff);/*return encrypted text */
return 0; /* indicate successful completeion */
]
Originally posted by djohnsto77
If you're using windows I think you should use "\r\n" instead of "\n"
[edit on 12/9/2005 by djohnsto77]
while ( buff[ i ] != '\0' )
[
buff[ i ] = buff[ i ] + shift_value + i++;
]
// Say hello
puts("**initializing.....**\n\n**linking..........**\n\n");
puts("Welcome agent Brown\n\n");
puts("You have accessed the Caesar Cipher program\n\n");
puts("Please enter the text you wish to encrypt: ");
// Get input from the user
// It is possible that the user may exceed our allocated space.
// We could address that but it would cloud the issue. TODO: for later
scanf("%s",&buff);
puts("\nEnter your encryption shift value (anything from +-1 to 25): ");
scanf("%d",&shift_value);
// We now have a string and a shift value
// TODO: Check for empty string and out of range value
// Determine how long the string is
encrypt_text_length = strlen(buff);
// Encrypted the text
for(i = 0; i < encrypt_text_length; i++)
[
buff = ShiftCharacter(buff,shift_value,i);
]
// Display the encrypted text for the user
printf("\nYour encrypted text is: %s",buff);
return 0; /* indicate successful completeion */
// This function will shift the character by the determined amount
// For our purpose we are only concerned with the letters a - z
char ShiftCharacter(char unencrypt,int shift_value,int offset)
[
char encrypted_char = unencrypt;
int i;
// Capital A - Z
if(unencrypt >= 'A' && unencrypt 'Z')
[
encrypted_char = 'A';
]
]
]
// Lowercase a - z
else if(unencrypt >= 'a' && unencrypt 'z')
[
encrypted_char = 'a';
]
]
]
return encrypted_char;
]
// casear_cipher.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include
#include
// Declare the function
char ShiftCharacter(char unencrypt,int shift_value,int offset);
int main(int argc, char* argv[])
[
char buff[1024];
int shift_value;
int encrypt_text_length;
int i;
// Say hello
puts("**initializing.....**\n\n**linking..........**\n\n");
puts("Welcome agent Brown\n\n");
puts("You have accessed the Caesar Cipher program\n\n");
puts("Please enter the text you wish to encrypt: ");
// Get input from the user
// It is possible that the user may exceed our allocated space.
// We could address that but it would cloud the issue. TODO: for later
scanf("%s",&buff);
puts("\nEnter your encryption shift value (anything from +-1 to 25): ");
scanf("%d",&shift_value);
// We now have a string and a shift value
// TODO: Check for empty string and out of range value
// Determine how long the string is
encrypt_text_length = strlen(buff);
// Encrypted the text
for(i = 0; i < encrypt_text_length; i++)
[
buff = ShiftCharacter(buff,shift_value,i);
]
// Display the encrypted text for the user
printf("\nYour encrypted text is: %s",buff);
return 0; /* indicate successful completeion */
]
// This function will shift the character by the determined amount
// For our purpose we are only concerned with the letters a - z
char ShiftCharacter(char unencrypt,int shift_value,int offset)
[
char encrypted_char;
int alphanumber; // The character as a number ( A = 1, B = 2, Z = 26 etc.)
// Capital A - Z
if(unencrypt >= 'A' && unencrypt = 'a' && unencrypt
buff = ShiftCharacter(buff,shift_value,i);
buff = ShiftCharacter(buff,shift_value,i);
buff[ i] = ShiftCharacter(buff[ i],shift_value,i);
Originally posted by Uber Fr0g
with spaces the program crashes. Same for punctuation. Is there a way to let it accept spaces and punctuation??
Originally posted by Uber Fr0g
ooh, that was it, im not used to the bbcode.
Quick question, when i type more than one word, example: hello world
with spaces the program crashes. Same for punctuation. Is there a way to let it accept spaces and punctuation??
char ShiftCharacter(char unencrypt,int shift_value,int offset)
[
// Initialize the return value to the original value
char encrypted_char = unencrypt;
if(unencrypt >= 'A' && unencrypt