Wednesday, October 04, 2017

Monoalphabetic Substitution Cipher in C++

#include <iostream>
#include <string>
#include <ctime>
#include <chrono>
#include <thread>

int main()
{

  char plain[100] = "devharsh";
  char cipher[100];
 
  char alphabets[26] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
  char mappings[26] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
 
  alphabets[26] = '\0';
  mappings[26] = '\0';
 
  std::cout << alphabets << "\n";
  std::cout << mappings << "\n";
 
  for (int i=0; i<26; i++)
  { 
    srand((int)time(0));
    std::this_thread::sleep_for(std::chrono::milliseconds(300));
    int irand = rand() % 26;
    char temp = mappings[i];
    mappings[i] = mappings[irand];
    mappings[irand] = temp;
  }
 
  std::cout << alphabets << "\n";
  std::cout << mappings << "\n";
 
  for (int i=0; i<sizeof(plain) / sizeof(char); i++)
  {
      for (int j=0; j<26; j++)
      {
          if (plain[i] == alphabets[j])
          {
              cipher[i] = mappings[j];
          }
      }
  }
 
  std::cout << plain << "\n";
  std::cout << cipher << "\n";

}

6 comments:

  1. Obviously, it's the dead genuine business of the veteran advertisers and market experts who hop into the fleeting trend of prescient investigation. Data Analytics Course

    ReplyDelete
  2. Attend The Data Analyst Course From ExcelR. Practical Data Analyst Course Sessions With Assured Placement Support From Experienced Faculty. ExcelR Offers The Data Analyst Course.
    Data Analyst Course

    ReplyDelete
  3. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog posts. ExcelR Data Analytics Courses In Pune Any way I’ll be subscribing to your feed and I hope you post again soon. Big thanks for the use

    ReplyDelete
  4. I wanted to leave a little comment to support you and wish you a good continuation. Wishing you the best of luck for all your blogging efforts.
    Data Analytics Course Pune wow... what a great blog, this writter who wrote this article it's realy a great blogger, this article so inspiring me to be a better person in some of them hope you will give more information on this topics in your next articles.
    I like viewing web sites which comprehend the price of delivering the excellent useful resource free of charge. I truly adored reading your posting. Thank you!

    ReplyDelete
  5. very well explained .I would like to thank you for the efforts you had made for writing this awesome article. This article inspired me to read more. keep it up.
    Simple Linear Regression
    Correlation vs covariance
    data science interview questions
    KNN Algorithm
    Logistic Regression explained

    ReplyDelete