Skip to main content

MY ENCODER / DECODER (The Way i Do it!)

/*
=======================
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

Popular posts from this blog

AP, GP Generator (using Linked List)

//Future advancements-> add save as file, in text or in a database option (for the sequences) //                      add more series to this //Programmer - Aditya Gupta #include<iostream> #include<stdlib.h> #include<math.h> //#include<fstream> //reqd when save support is added to this! using namespace std; struct Node{ int data; Node* next; }; void inline title(void){ system("cls"); cout<<"\tNAMASTE!...\n\nProgram-AP,GP Generator\nPrograammer - MR. ADITYA GUPTA (TEChY 3)\n\n"; } class List{ //NOTE: I HAVE REMOVED ALL COMMENTS, REFER TO THE LINKED LIST TEMPLATE FOR DETAILED COMMENTS             //here only generator specific comments are there, and that too which are not in template Node *top,*rear; public: void Push(int dat); int isempty(); int search(int dat); int noofelements(); void Pop(); //CAUTION- will decrease number of terms by 1 each time it runs, and pushing the last element again will be same

Using 'ls' command as a replacement of 'find'

Advantage over find - Actually not probably in terms of speed, but... only point of this is that it's an observation, but... you can do like 'search only in' */*/*Programs* , /*/*Programs*/* , this may compensate the extra time took by using two commands 1. To search in current folder only (1 level... only this folder, no subfolder)     Type... ls | grep Search_Term 2. To search in current folder only (till level 2... this folder + subfolder)     Type... ls * | grep Search_Term #ls and ls * are NOT same! 3. To search in current folder only (till level 3... this folder + subfolder + subfolder)     Type... ls */* | grep Search_Term 4. To search in current folder only (till level 4... this folder + subfolder + subfolder + subfolder)     Type... ls */*/* | grep Search_Term ... and so on... FORMULA - To search till 'n' level (considering current folder as 1)... go till (n-1) stars If wanting to search whole disk... better type stars, like this... ls * ** *** **** *****

More_Inferences_in_C++(1Aug'19-16thOct'19)

Programmer/Tester- Aditya Gupta (aka Techy3.5 :-) I used g++ to compile these on linux 1. Type casting of floating point numeral to integer (either automatic or by type casting)- Conversion of floating point to integer is by taking the GIF (Greatest Integer Funtion) and NOT ROUNDING OFF Greatest Integer Function(Maths,12th) it gives the integer part when the original number is written as integer+fractional part (where fractional part is less than 1 but positive) 2. NEsted MultiLine Comment [actually wont work as expected?!] if you do this in C++.... /*  blah /*blah blah blah*/ blah*/ the last blah will be visible to the compiler!!! (Inference- Multiline-Comment ends whenever */ is encountered, no matter where!!)NEsted MultiLine Comment 3. Size of various types (of C++) on 'Linux' Mint - (and same as in later versions of windows, and most PCs nowadays) char - 1 int - 4  (and: short - 2, unsigned long - 8) long long - 8 float - 4 double - 8 (and: lo