
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
Polybius Square Cipher in C++
In this problem, we are given a string and we have to find its integer encryption using the Polybius Square Cipher.
Polybius Square Cipher
It is a table that is used for the conversion of letters into numbers. The table for English encryption is a 5X5 table i.e. contains 25 cells for 26 alphabets of an English dictionary. The letters i and j are kept together in a single cell.
The following table shows a Polybius square Cipher −
1 | 2 | 3 | 4 | 5 | |
1 | A | B | C | D | E |
2 | F | G | H | I, J | K |
3 | L | M | N | O | P |
4 | Q | R | S | T | U |
5 | V | W | X | Y | Z |
The letter of the tables can be randomized. Also, the size of the table can be changed based on the number of alphabets of the language.
Let’s take an example to understand the problem,
Input − Hello
Output − 2315313134
To solve this problem, we will create a program to take each pair of numbers and then check for the corresponding letter.
Example
Program to show the illustration of our solution −
#include <cmath> #include <iostream> using namespace std; void LetterToNumber(string str) { int R, C; for (int i = 0; str[i]; i++) { R = ceil((str[i] - 'a') / 5) + 1; C = ((str[i] - 'a') % 5) + 1; if (str[i] == 'k') { R = R - 1; C = 5 - C + 1; } else if (str[i] >= 'j') { if (C == 1) { C = 6; R = R - 1; } C = C - 1; } cout<<R<<C; } cout << endl; } int main() { string str = "tutorialspoint"; cout<<"The numeric encryption of string '"<<str<<"' is : "; LetterToNumber(str); return 0; }
Output
The numeric encryption of string 'tutorialspoint' is: 4445443442241131433534243344
- Related Articles
- XOR Cipher in C++
- C++ Program to Implement Affine Cipher
- Difference between Block Cipher and Stream Cipher
- Difference between Monoalphabetic Cipher and Polyalphabetic Cipher
- Atbash cipher in Python
- Caesar Cipher in Python
- Bifid Cipher in Cryptography
- Caesar Cipher in Cryptography
- Difference between Substitution Cipher Technique and Transposition Cipher Technique
- What is the comparison between Stream Cipher and Block Cipher in information security?
- C++ Program to Encode a Message Using Playfair Cipher
- The Symmetric Cipher Model
- Block Cipher Design Principles
- C++ Program to Decode a Message Encoded Using Playfair Cipher
- What is Block Cipher in information security?
