C++ Articles - Page 609 of 717

C++ Program to Implement the Hill Cypher

Smita Kapse
Updated on 30-Jul-2019 22:30:26

8K+ Views

Based on linear algebra Hill cipher is a polygraphic substitution cipher in cryptography.To encrypt message: The key string and message string are represented as matrix form. They are multiplied then, against modulo 26. The key matrix should have inverse to decrypt the message.To decrypt message: The encrypted message is multiplied by inverse key matrix used for encryption against modulo 26 to get decrypt message.For exampleKey matrix1 0 1 2 4 0 3 5 6Message string ‘ABC’ in matrix form −0 1 2For encryptionAfter multiplying above two matrices we get, 2 4 17Which will be the encrypted message ‘CER’For decryptionInverse of ... Read More

C++ Program to Implement the RSA Algorithm

Anvi Jain
Updated on 17-May-2021 06:43:38

19K+ Views

RSA is an asymmetric cryptography algorithm which works on two keys-public key and private key.AlgorithmsBegin    1. Choose two prime numbers p and q.    2. Compute n = p*q.    3. Calculate phi = (p-1) * (q-1).    4. Choose an integer e such that 1 < e < phi(n) and gcd(e, phi(n)) = 1; i.e., e and phi(n) are coprime.    5. Calculate d as d ≡ e−1 (mod phi(n)); here, d is the modular multiplicative inverse of e modulo phi(n).    6. For encryption, c = me mod n, where m = original message.    7. For ... Read More

C++ Program to Decode a Message Encoded Using Playfair Cipher

Nishtha Thakur
Updated on 30-Jul-2019 22:30:26

507 Views

In this scheme, pairs of letters are encrypted, instead of single letters as in the case of simple substitution cipher.In playfair cipher, initially a key table is created. The key table is a 5×5 grid of alphabets that acts as the key for encrypting the plaintext. Each of the 25 alphabets must be unique and one letter of the alphabet (usually J) is omitted from the table as we need only 25 alphabets instead of 26. If the plaintext contains J, then it is replaced by I.The sender and the receiver deicide on a particular key, say ‘tutorials’. In a ... Read More

C++ Program to Encode a Message Using Playfair Cipher

Smita Kapse
Updated on 30-Jul-2019 22:30:26

6K+ Views

In this scheme, pairs of letters are encrypted, instead of single letters as in the case of simple substitution cipher.In playfair cipher, initially a key table is created. The key table is a 5×5 grid of alphabets that acts as the key for encrypting the plaintext. Each of the 25 alphabets must be unique and one letter of the alphabet (usually J) is omitted from the table as we need only 25 alphabets instead of 26. If the plaintext contains J, then it is replaced by I.The sender and the receiver deicide on a particular key, say ‘tutorials’. In a ... Read More

C++ Program to Implement Caesar Cypher

Anvi Jain
Updated on 30-Jul-2019 22:30:26

28K+ Views

It is a mono-alphabetic cipher wherein each letter of the plaintext is substituted by another letter to form the ciphertext. It is a simplest form of substitution cipher scheme.This cryptosystem is generally referred to as the Shift Cipher. The concept is to replace each alphabet by another alphabet which is ‘shifted’ by some fixed number between 0 and 25.For this type of scheme, both sender and receiver agree on a ‘secret shift number’ for shifting the alphabet. This number which is between 0 and 25 becomes the key of encryption.The name ‘Caesar Cipher’ is occasionally used to describe the Shift ... Read More

C++ Program to Perform Finite State Automaton based Search

Farhan Muhamed
Updated on 18-Jun-2025 19:18:27

988 Views

An automaton with a finite number of states is called a Finite Automaton. We can use a Finite State Automaton (FSA) to perform optimized pattern search operation on a string. This article will discuss how to implement a Finite State Automaton based search in C++. Problem Statement: Given two strings text[] and pattern[], we want to find all occurrences of the pattern in the text using a Finite State Automaton. // Input Strings text[] = "tutorialsPoint provides premium tutorials on various topics" pattern[] = "tutorials" // Output Pattern found at index 0 and 32 Finite State ... Read More

C++ Program to Repeatedly Search the Same Text (such as Bible by building a Data Structure)

Anvi Jain
Updated on 30-Jul-2019 22:30:26

190 Views

This is a C++ program to repeatedly search the same text.AlgorithmsBegin    Take the original string and pattern to be searched as input.    org_len = store the length of original string    pat_len = store the length of pattern    for i = 0 to (org_len - pat_len)       for j = 0 to pat_len - 1          if (org[i + j] != patt[j])             if (j == pat_len)                Increase m.       Print the position at which the pattern is ... Read More

C++ Program to Solve N-Queen Problem

Farhan Muhamed
Updated on 17-Jun-2025 19:15:44

13K+ Views

The N-Queens problem is a puzzle where we need to place N queens on an N x N chessboard such that no two queens attack each other. A queen will attack another queen if they are in the same row, column, or diagonal. In this problem, you are given a value of N, and you need find possible arrangements for N queens on N x N chessboard. For example, Consider that we have a chessboard of size 4 x 4. In this case, we can place maximum 4 queens on the chessboard such that no two queens attack ... Read More

C++ Program to Check if a Given Set of Three Points Lie on a Single Line or Not

Farhan Muhamed
Updated on 16-Jun-2025 18:09:45

883 Views

In this problem, you are given three coordinates in a 2D plane, and you need to check if these three points are collinear, meaning they lie on a single straight line. There are two approaches to solve this problem. In this article, we will explain both the approaches with example code in C++. // Input: Coordinates of three points points = {{2, 3}, {4, 6}, {6, 9}}; // Output The points are collinear. Check if Three Points are Collinear If three points lie on a single line, then the points are called as collinear points. ... Read More

C++ Program to Show the Duality Transformation of Line and Point

Farhan Muhamed
Updated on 16-Jun-2025 18:09:29

291 Views

The duality transformation is concept in computational geometry that maps coordinate points to lines and lines to coordinate points. In this article, we will learn all about the duality transformation of lines and points, and implement C++ code to show this transformation. What is Duality Transformation? The duality transformation is a process that converts 2 dimensional lines and coordinates into dual plane. In this transformation, a point in the 2D plane can be represented as a line in the dual space, and a line in the 2D plane can be represented as a point in the dual space. This ... Read More

Advertisements