Found 7347 Articles for C++

C++ Program to Implement Trie

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

1K+ Views

Here we shall discuss a C++ Program to implement Trie. It is a tree based data structure, used for efficient retrieval of a key in a large data-set of strings.Functions and pseudocodesBegin function insert() :    If key not present, inserts key into trie. If the key is prefix of trie node, just mark leaf node. End Begin function deleteNode()    If tree is empty then return null.    If last character of the key is being processed,       then that node will be no more end of string after deleting it.       If given key ... Read More

C++ Program to Find number of Ways to Partition a word such that each word is a Palindrome

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

139 Views

Here we shall discuss a C++ Program to find number of ways to Partition a word in such a way that each word is a Palindrome.AlgorithmsBegin    Take the word as input.    Function partitionadd(vector &u, string &s, vector &tmp, int index):    if (index == 0)       tmp.clear()    for i = index to length-1       st = st + s[i]       if (checkPalin(st))          tmp.push_back(st)          if (i+1 < length)             partitionadd(u, s, tmp, i+1)          else   ... Read More

C++ Program to Find the Longest Prefix Matching of a Given Sequence

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

444 Views

Here we shall discuss a C++ program to find the Longest Subsequence Common to All Sequences in a Set of Sequences.AlgorithmsBegin Take the array of strings as input. function matchedPrefixtill(): find the matched prefix between string s1 and s2 :    n1 = store length of string s1.    n2 = store length of string s2.    for i = 0, j = 0 to i

C++ Program to Find the Shortest Supersequence that Contains Two or more Sequences as Subsequences

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

111 Views

Here we shall discuss a C++ Program to find the Shortest Supersequence that contains two or more Sequences as Subsequences.AlgorithmBegin    function ShortestSubSeq() returns supersequence of A and B:    1) Declare an array ss[i][j] which contains length of shortest supersequence for A[0 .. i-1] and B[0 .. j-1].    2) Find the length of the possible supersequence in bottom up manner using recursion.    3) Declare an array ss[i][j] which stores length of shortest supersequence for A[0 .. i-1] and B[0 .. j-1] in index.    4) Declare a string s to store the shortest subsequence.    5) Initialize ... Read More

C++ Program to Find the Longest Subsequence Common to All Sequences in a Set of Sequences

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

114 Views

Here we shall discuss a C++ program to find the Longest Subsequence Common to All Sequences in a Set of Sequences.AlgorithmsBegin Take the array of strings as input. function matchedPrefixtill(): find the matched prefix between string s1 and s2 :    n1 = store length of string s1.    n2 = store length of string s2.    for i = 0, j = 0 to i

C++ Program to Implement Kadane’s Algorithm

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

1K+ Views

Kadane’s algorithm is used to find out the maximum subarray sum from an array of integers. Here we shall discuss a C++ program to implement this algorithm.AlgorithmBegin Function kadanes(int array[], int length):    Initialize    highestMax = 0    currentElementMax = 0    for i = 0 to length-1       currentElementMax = max(array[i], currentElementMax + array[i])       highestMax = max(highestMax, currentElementMax)    return highestMax EndExample#include using namespace std; int kadanes(int array[], int length) {    int highestMax = 0;    int currentElementMax = 0;    for(int i = 0; i < length; i++){       ... Read More

C++ Program to Implement Affine Cipher

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

2K+ Views

In the Affine cipher, each letter in an alphabet is mapped to its numeric equivalent, is a type of monoalphabetic substitution cipher. Encryption is done using a simple mathematical function and converted back to a letter.The letters of an alphabet of size m are first mapped to the integers in the range 0 … m-1, in the Affine cipher, The ‘key’ for the Affine cipher consists of 2 numbers, a and b. a should be chosen to be relatively prime to m.EncryptionTo transform the integer, it uses modular arithmetic that each plaintext letter corresponds to into another integer that correspond ... Read More

C++ Program to Implement the Vigenere Cypher

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

6K+ Views

Vigenere Cipher is a kind of polyalphabetic substitution method of encrypting alphabetic text.Vigenere Cipher Table is used in which alphabets from A to Z are written in 26 rows, for encryption and decryption in this method.EncryptionKey: WELCOMEMessage: ThisistutorialspointHere we have to obtain a key by repeating the given key till its length becomes equal to original message length.For encryption take first letter of message and key i.e. T and W. Take the alphabet in Vigenere Cipher Table where T row and W column coincides i.e. P.Repeat the same process for all remaining alphabets in message text.Finally, the encrypted message text ... Read More

C++ Program to Implement the Hill Cypher

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

6K+ 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

14K+ 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

Advertisements