Total members 11889 |It is currently Thu Mar 28, 2024 10:30 pm Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





Ceasar encryption-decryption-cipher-decipher C code implementation :
cpp code
#include <stdio.h>
#include <string.h>

void menu(void){
printf("Please enter a number: \n"
"1-Encrypt\n"
"2-Decrypt\n"
"3-Exit\n"
"prompt > ");
fflush( stdout );
}

int getchoice(void){
char buff[BUFSIZ];
int choice = 0;
do {
menu();
if(fgets( buff, sizeof buff, stdin ) != NULL){
/* success reading a line, does it make sense? */
if(sscanf( buff, "%d", &choice) != 1){
printf("Enter a number\n");
}
}else{
/* user EOF, just exit now */
choice = 3;
}
}while(choice < 1 || choice > 3);
return choice;
}

void encode(void){
char buff[BUFSIZ];
int i = 0;
int shift_value;
printf( "Doing encrypt\n" );
printf("\nPlease enter the text you wish to encrypt CAPS LOCK ONLY: ");
fgets(buff, sizeof(buff), stdin);
printf("\nEnter your encryption shift value (anything from +1 to 25): ");
scanf("%i", &shift_value);
while(buff[i] != '\0'){
if(buff[i] >= 'A' && buff[i] <= 'Z'){
buff[i] = 'A' + (buff[i] - 'A' + shift_value) % 26;
}
i++;
}
printf("\n Your encrypted text is: %s \n", buff);
}

void decode(void){
char buff[BUFSIZ];
int i = 0;
int shift_value;
printf( "Doing decrypt\n" );
printf("\nPlease enter the text you wish to decrypt CAPS LOCK ONLY: ");
fgets(buff, sizeof(buff), stdin);
printf("\nEnter your encryption shift value (anything from +1 to 25): ");
scanf ("%i", &shift_value);

while(buff[i] != '\0'){
if(buff[i] >= 'A' && buff[i] <= 'Z'){
int c = buff[i] - 'A' - shift_value;
if(c < 0)
c += 26;
buff[i] = 'A' + c % 26;
}
i++;
}
printf("\nYour decrypted text is: %s \n", buff);
}

int main(){
int choice;
while((choice=getchoice()) != 3 ){
if(choice == 1){
encode();
}else{
if(choice == 2){
decode();
}
}
}
return 0;
}




_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time
Post new topic Reply to topic  [ 1 post ] 

  Related Posts  to : Ceasar encryption-decryption-cipher-decipher code
 Encryption and Decryption encryption Affine cipher code     -  
 Row Transposition cipher - encryption-decryption java     -  
 Row Transposition cipher - encryption-decryption Csharp(C#)     -  
 RSA encryption decryption cipher algorithm java     -  
 Advanced Encryption Standard (AES)-Example-Decipher (Step2)     -  
 encryption/ decryption without key using C++     -  
 encryption and decryption in c++     -  
 codes for encryption/decryption algorithms     -  
 Advanced Encryption Standard (AES)-Example-Cipher (Step1)     -  
 polyalphabetic cipher java code     -  



Topic Tags

C++ Algorithms
cron





Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com