Thursday 29 September 2016

C++ Convert 4 character plain text to cypher text

Always remember to get desired output from machine you have to first provide significant solutions to respective problems so i proposed following option

first thing is very important to create algo & implement Algo in any language . I don't want to discuss in depth but main purpose of this program is to accomplish basic working of simple text(such as string) to cypher(desired alphabates encryption) its not efficient algo but i have written for poor programmers. You know copy paste programmers are qualified professional degree holder but behind the scene they are nothing more than copy paste so i suggest my students , followers don't learn programming by heart just give some precious honour time for it which leads you to get huge grip in easly making of logical solution for simple programs but perform logical problems that are part of programming . every one can write Code
with perfect logic & unsatisfactory logic can leads to time waste results


 have lack of interest in programming they just want to get basic idea behind the logic.


i initialized & declared character Array of 4 size.
use loop to get single character in each array index
the key_size is used to apply on each character to apply cypher to get desired cyper character

for example

plain text

a               b                        c                    d

which means

array[0] has character a
array[1] has character b
array[2] has character c
array[3] has character d

key_size = 2 let example

desired output must be 


c          d           e            f             





Code:-

#include <iostream>
#include<conio.h>
using namespace std;

void main()
{
char ch[4]; //
int i = 0;
cout << "Please enter the plan text : ";
while (i<4)
{
cout << endl << "enter the letter # :" << i << endl;
cin >> ch[i];
i++;
}
char Start_ch = 'a';
char End_ch = 'z';
int KeySize = 2;

cout << "Please enter the Key Size : ";
cin >> KeySize;
char ab = 'x';

/*to get the cypher text we need to perform loop on all character present in character array*/
for (int j = 0; j<4; j++)
{
/*we initialize the variable integer with i that can start with 0 for each letter to perform logic*/
int i = 1;
while (i <= KeySize)
{
/* character is less then z letter it will remain continue*/
if (ch[j]<'z')
{
  ab = ch[j]; // get the current character from array to character variable that is temp
ab++;  //increment the array variable 1 to against keysize
ch[j] = ab;  //override the exsisting variable with increment character variable
i++;
}
/*the character who exceeds the letter z then it is reset from a to onward */
else if (ch[j] == 'z')
{
ch[j] = 'a';
i++;
}
}
}
cout << endl;
cout << "Cypher text is as under : ";
for (int i = 0; i<4; i++){
cout << ch[i];
}
_getch();
}

Output:-