#include<iostream>
#include<fstream>
using namespace std;

void inverse_gematria(int, int[]);
void inverse_gematria(int, int[], int[]);
void rotation(int, int[], int);
void normal(int, int[]);
void vignere(int, int[]);
const string GEMATRIA[26] = {"X","E","L","C","G","B","F","N","O","P","Q","R","S","T","U","V","W","Y","Z","A","D","H","I","J","M","Z"};

int main()
{

    int x, value[80], inv[80], ctr = 0; //Maximum 80 characters

    cout<<"Enter the ID, invalid to stop: ";

    while (cin>>x)
    {
        if (x < 0 || x > 25)
            break;
        ctr++; //Track the indices in an array
        value[ctr-1] = x;
    }

    cout<<"Normal: ";
    normal(ctr, value);

    cout<<"Inverse Gematria: ";
    inverse_gematria(ctr, value);

    for (int i = 1; i < 26; i++)
    {
        cout<<"Rotate by "<<i<<": ";
        rotation(ctr, value, i);
    }

    for (int i = 25; i >= 1; i--)
    {
        cout<<"Rotate Inverse (Inverse with key) by "<<26 - i<<": ";
        inverse_gematria(ctr,value,inv);
        rotation(ctr, inv, 26 - i);
    }

    cout<<"Vigenere:\n";
    vignere(ctr, value);

    cout<<"Press Any Number then Enter to exit...\n";
    cin>>x;



}

void vignere(int ctr, int value[80])
{
    int key[80], ctr2 = 0, decrypted[80];
    cout<<"Enter the key: ";
    while(cin>>key[ctr2])
    {
        if (key[ctr2]< 0 || key[ctr2] > 25)
            break;
        ctr2++;
    }
    if (ctr2 < ctr)
    {
        int x = ctr - ctr2;
        for (int i = 0; i < x; i++)
        {
            key[ctr2+i] = key[i];
        }

    }

    /*
    cout<<"Key is: ";

    for(int i = 0; i < ctr; i++)
        cout<<key[i]<<" ";
    cout<<endl;*/

    for (int i = 0; i < ctr; i++)
    {
        decrypted[i] = value[i] - key[i];
        if (decrypted[i] < 0)
            decrypted[i] += 26;

        cout<<GEMATRIA[decrypted[i]]<<" ";
    }
    cout<<endl;


}

void normal(int ctr, int value[80])
{
    for (int i = 0; i < ctr; i++)
        cout<<GEMATRIA[value[i]]<<" ";
    cout<<endl;
}

void rotation(int ctr, int value[80], int index)
{
    for (int i = 0; i < ctr; i++)
    {
        cout<<GEMATRIA[(value[i]+index)%26]<<" ";
    }
    cout<<endl;
}

void inverse_gematria(int ctr, int value[80])
{
    for (int i = 0; i < ctr; i++)
    {
        cout<<GEMATRIA[26-value[i]-1]<<" ";
    }
    cout<<endl;
}

void inverse_gematria(int ctr, int value[80], int inv[80])
{
    for (int i = 0; i < ctr; i++)
    {
        inv[i] = 26-value[i]-1;
    }
} 

C++ Online Compiler

Write, Run & Share C++ code online using OneCompiler's C++ online compiler for free. It's one of the robust, feature-rich online compilers for C++ language, running on the latest version 17. Getting started with the OneCompiler's C++ compiler is simple and pretty fast. The editor shows sample boilerplate code when you choose language as C++ and start coding!

Read inputs from stdin

OneCompiler's C++ online compiler supports stdin and users can give inputs to programs using the STDIN textbox under the I/O tab. Following is a sample program which takes name as input and print your name with hello.

#include <iostream>
#include <string>
using namespace std;

int main() 
{
    string name;
    cout << "Enter name:";
    getline (cin, name);
    cout << "Hello " << name;
    return 0;
}

About C++

C++ is a widely used middle-level programming language.

  • Supports different platforms like Windows, various Linux flavours, MacOS etc
  • C++ supports OOPS concepts like Inheritance, Polymorphism, Encapsulation and Abstraction.
  • Case-sensitive
  • C++ is a compiler based language
  • C++ supports structured programming language
  • C++ provides alot of inbuilt functions and also supports dynamic memory allocation.
  • Like C, C++ also allows you to play with memory using Pointers.

Syntax help

Loops

1. If-Else:

When ever you want to perform a set of operations based on a condition If-Else is used.

if(conditional-expression) {
   //code
}
else {
   //code
}

You can also use if-else for nested Ifs and If-Else-If ladder when multiple conditions are to be performed on a single variable.

2. Switch:

Switch is an alternative to If-Else-If ladder.

switch(conditional-expression){    
case value1:    
 // code    
 break;  // optional  
case value2:    
 // code    
 break;  // optional  
......    
    
default:     
 code to be executed when all the above cases are not matched;    
} 

3. For:

For loop is used to iterate a set of statements based on a condition.

for(Initialization; Condition; Increment/decrement){  
  //code  
} 

4. While:

While is also used to iterate a set of statements based on a condition. Usually while is preferred when number of iterations are not known in advance.

while (condition) {  
// code 
}  

5. Do-While:

Do-while is also used to iterate a set of statements based on a condition. It is mostly used when you need to execute the statements atleast once.

do {  
 // code 
} while (condition); 

Functions

Function is a sub-routine which contains set of statements. Usually functions are written when multiple calls are required to same set of statements which increases re-usuability and modularity. Function gets run only when it is called.

How to declare a Function:

return_type function_name(parameters);

How to call a Function:

function_name (parameters)

How to define a Function:

return_type function_name(parameters) {  
 // code
}