/*
=======================
MY ENCODER / DECODER
=======================
-------------------------
Further ideas - 1. Encode whole of a file given by user (but, how to set the file stream to input a file name given in run time, and not a predefined name)
2. Make it more advance by using many encryption techniques, and let the program chose any one of them randomly, taki khud programmer ko bhi pata na ho ki kaun se coding se decode hoga, and set a password in the program bnefore askig to decode, because that will be the only way
3. Currently i am supporting sentence input of maximum 101 characters, increase it to unlimited using stacks, queues, etc.
4. Add support for encoding and decoding other characters as well
5. In the print() function - Add a condition (maybe using iomanip.h) so as to print first character as capital, in case of printing decoded string
6.In the ctb() function -
{i} Try to remove the assumption by modifying the function
{ii} Now... How to convert a decimal number into a binary number
-------------------------
*/
#include<iostream>
#include<stdlib.h>
using namespace std;
int i;
void title(void)
{
system("cls");
cout<<"\n\n\tMY ENCODER/DECODER\n\nMade by: Aditya Gupta\n\n";
}
void input(char &temp[]);
void input(int &tempi[]);
void encode(char, char&);
void decode(char, char&);
char cfb(int); //cfb=convert_from_binary
int ctb(char); //ctb=convert_to_binary
void print(char); //could have been done by using string.h header, but anyways, i made one for myself
void print(int)
int main()
{
retry:
title(); int ch; char En[101]; int Dc[401]; //'to be Encoded' and 'to be Decoded' strings [It's a bit confusing, i know, but who matters, since users doesnt see the code, make the user experience better! :)]
cout<<"Choose from below options (Enter choice number) :"
<<"1. Encode a sentence"
<<"2. Decode a sentence";
cin>>ch;
switch(ch)
{
case 1: cout<<"Enter the string :"; input(&En); encode(En,&Dc); print(Dc);
case 2: cout<<"Enter the string [press spaces between different words] :"; input(&Dc); decode(Dc,&En); print(En);
default: cerr<<"TRY AGAIN..."; system(pause); goto retry;
}
//the "my way" starts from here;
cout<<
return 0;
}
void input(char &temp[])
{
cout<<"Now enter the string (enter '.' to stop entering and submit)[the '.' will not be counted]";
for(i=0;i<101;i++)
{
cin>>temp[i];
if(temp[i]=='.') break; //dont forget to include this condition also when printing so that this also doesnt get encoded!
}
}
void input(int &tempi[])
{
cout<<"Now enter the string (enter 2 to stop entering and submit)[the 2 will not be counted]";
for(i=0;i<101;i++)
{
cin>>temp[i];
if(temp[i]==2) break; //dont forget to include this condition also when printing so that this also doesnt get encoded!
}
}
void encode(char temp1, char &temp2)
{
i=0;
while(temp1[i]!='.')
//temp[2]= //This now requires a function to give the binary equivalent of every number
}
void decode(char temp2, char &temp1)
{
i=0; int flag=4;
char t[5]; //initialize all of them with 0; //the maximum 5 numbers of a bianry unit, representing a word;
while(temp2[i]!=2)
{for(int j=0; temp2[j]!=' ',) //OH SHIT! INTegeres CANT STORE COMMA AND SPACES
{
t[flag]=temp2[j];
j++;
if(temp2[j+1]==' ') { temp1[i]=cfb(t[5]); flag=0; break;
}
flag--;
} i++;
}
}
void print(char temp3)
{ i=0;
while(temp3[i]!='.')
{ cout<<temp3[i]; i++; }
}
void print(int temp3i)
{ i=0;
while(temp3i[i]!='.')
{ cout<<temp3i[i]; i++; }
}
char cfb(int bvalues[]) // 'a'=97 and 'A'=65
{
int sum;
sum=bvalues[4]*1+bvalues[3]*2+bvalues[2]*4+bvalues[1]*8+bvalues[0]*16;
if(sum>26){ cerr<<"This isnt a supported character"; exit(3); }
char tmpc=char(96+sum); //temporary character
return tmpc;
}
int ctb(char cvalues[]) //This funtion will be returning an array of size 5
{
int sum;
sum=int(char)-96; //Assuming only 'SMALL letters have been typed'
//Now... how to convert the number 'sum' into a binary number
}
//this isnt complete yet, due to ''time shortage'
//actually, i am in class 12th, and preparing for very important exams, and there has always been a shortage of time, but there's no one to blame for that, and i dont blame others either
//I WILL DEFINIETLY COMPLETE mY PROGRAM LATER ("Later is a bit harsh! actually :-( ")
//But in the meantime, if anyone of you can give a helpful suggetion, i will be very thanful to YOU! :)
//BTW, THIS PROGRAM IS QUITE COMPLETE IN LOGIC, WHICH I HAVE WROTE IN THE PROGRAM ITSELF, including ideas for further development :) THANX!
=======================
MY ENCODER / DECODER
=======================
-------------------------
Further ideas - 1. Encode whole of a file given by user (but, how to set the file stream to input a file name given in run time, and not a predefined name)
2. Make it more advance by using many encryption techniques, and let the program chose any one of them randomly, taki khud programmer ko bhi pata na ho ki kaun se coding se decode hoga, and set a password in the program bnefore askig to decode, because that will be the only way
3. Currently i am supporting sentence input of maximum 101 characters, increase it to unlimited using stacks, queues, etc.
4. Add support for encoding and decoding other characters as well
5. In the print() function - Add a condition (maybe using iomanip.h) so as to print first character as capital, in case of printing decoded string
6.In the ctb() function -
{i} Try to remove the assumption by modifying the function
{ii} Now... How to convert a decimal number into a binary number
-------------------------
*/
#include<iostream>
#include<stdlib.h>
using namespace std;
int i;
void title(void)
{
system("cls");
cout<<"\n\n\tMY ENCODER/DECODER\n\nMade by: Aditya Gupta\n\n";
}
void input(char &temp[]);
void input(int &tempi[]);
void encode(char, char&);
void decode(char, char&);
char cfb(int); //cfb=convert_from_binary
int ctb(char); //ctb=convert_to_binary
void print(char); //could have been done by using string.h header, but anyways, i made one for myself
void print(int)
int main()
{
retry:
title(); int ch; char En[101]; int Dc[401]; //'to be Encoded' and 'to be Decoded' strings [It's a bit confusing, i know, but who matters, since users doesnt see the code, make the user experience better! :)]
cout<<"Choose from below options (Enter choice number) :"
<<"1. Encode a sentence"
<<"2. Decode a sentence";
cin>>ch;
switch(ch)
{
case 1: cout<<"Enter the string :"; input(&En); encode(En,&Dc); print(Dc);
case 2: cout<<"Enter the string [press spaces between different words] :"; input(&Dc); decode(Dc,&En); print(En);
default: cerr<<"TRY AGAIN..."; system(pause); goto retry;
}
//the "my way" starts from here;
cout<<
return 0;
}
void input(char &temp[])
{
cout<<"Now enter the string (enter '.' to stop entering and submit)[the '.' will not be counted]";
for(i=0;i<101;i++)
{
cin>>temp[i];
if(temp[i]=='.') break; //dont forget to include this condition also when printing so that this also doesnt get encoded!
}
}
void input(int &tempi[])
{
cout<<"Now enter the string (enter 2 to stop entering and submit)[the 2 will not be counted]";
for(i=0;i<101;i++)
{
cin>>temp[i];
if(temp[i]==2) break; //dont forget to include this condition also when printing so that this also doesnt get encoded!
}
}
void encode(char temp1, char &temp2)
{
i=0;
while(temp1[i]!='.')
//temp[2]= //This now requires a function to give the binary equivalent of every number
}
void decode(char temp2, char &temp1)
{
i=0; int flag=4;
char t[5]; //initialize all of them with 0; //the maximum 5 numbers of a bianry unit, representing a word;
while(temp2[i]!=2)
{for(int j=0; temp2[j]!=' ',) //OH SHIT! INTegeres CANT STORE COMMA AND SPACES
{
t[flag]=temp2[j];
j++;
if(temp2[j+1]==' ') { temp1[i]=cfb(t[5]); flag=0; break;
}
flag--;
} i++;
}
}
void print(char temp3)
{ i=0;
while(temp3[i]!='.')
{ cout<<temp3[i]; i++; }
}
void print(int temp3i)
{ i=0;
while(temp3i[i]!='.')
{ cout<<temp3i[i]; i++; }
}
char cfb(int bvalues[]) // 'a'=97 and 'A'=65
{
int sum;
sum=bvalues[4]*1+bvalues[3]*2+bvalues[2]*4+bvalues[1]*8+bvalues[0]*16;
if(sum>26){ cerr<<"This isnt a supported character"; exit(3); }
char tmpc=char(96+sum); //temporary character
return tmpc;
}
int ctb(char cvalues[]) //This funtion will be returning an array of size 5
{
int sum;
sum=int(char)-96; //Assuming only 'SMALL letters have been typed'
//Now... how to convert the number 'sum' into a binary number
}
//this isnt complete yet, due to ''time shortage'
//actually, i am in class 12th, and preparing for very important exams, and there has always been a shortage of time, but there's no one to blame for that, and i dont blame others either
//I WILL DEFINIETLY COMPLETE mY PROGRAM LATER ("Later is a bit harsh! actually :-( ")
//But in the meantime, if anyone of you can give a helpful suggetion, i will be very thanful to YOU! :)
//BTW, THIS PROGRAM IS QUITE COMPLETE IN LOGIC, WHICH I HAVE WROTE IN THE PROGRAM ITSELF, including ideas for further development :) THANX!
Comments
Post a Comment
You are free to leave any kind of suggestion, or improvement. It doesn't require you to sign in either.