j0h

SimpleNullCipher

j0h
May 26th, 2023 (edited)
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.75 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4. /*
  5.  * A Simple null cipher generator
  6.  * Usage: null <input file>
  7.  * output words where first letters assemble to spell the enciphered words.
  8.  *
  9.  * example:
  10.  * text input: hello world
  11.  *
  12.  * Output:
  13.  * haired erotic leering live occult
  14.  * willful occupy reduce love deviation
  15.  * */
  16.  
  17. //Random index: rand()%max + 1 -Min) + min
  18. int r() {
  19.    // srand(time(NULL));
  20.     return (rand() % (4 - 0 + 1)) + 0;
  21. }
  22. //Simple dictionary: 5 words starting with a letter. 5*Char
  23. char simpDict[][130] = {
  24.     "ardent","arcane","arsenic","archaic","archived",
  25.     "bravo","brave","break","because","beer",
  26.     "cats","could","clouds","can","cap",
  27.     "damn","deviation","drugs","drab","drone",
  28.     "esoteric","erotic","error","exit","excited",
  29.     "foxtrot","fornicate","found","feet","feel",
  30.     "games","gains","great","greed","green",
  31.     "hello","haired","honor","home","hope",
  32.     "idiot","incinerate","ingest","ingrate","incantation",
  33.     "jump","jam","jive","jeer","jest",
  34.     "kill","knife","know","king","knots",
  35.     "love","live","life","leering","lecherously",
  36.     "more","many","make","mandible","masticate",
  37.     "no","nope","nothing","nods","near",
  38.     "occult","occupy","octopus","odd","oops",
  39.     "pride","pain","peers","perplex","pipe",
  40.     "question","queer","quintessentially","quintuple","quine",
  41.     "risk","ran","rampant","reduce","reuse",
  42.     "stop","sting","stare","stave","steal",
  43.     "times","tear","tedious","ten","technology",
  44.     "umbrella","up","under","uncover","ubiquitous",
  45.     "van","veer","vaccinate","variable","vacuum",
  46.     "we","would","wish","willful","woes",
  47.     "xylem","xii","xylem","xerxes","xysts",
  48.     "year","yes","yak","yarn","you",
  49.     "zoom","zeus","zest","zeta","zygote"
  50. };
  51.  
  52. //assuming all lower for now,
  53. void getNC(char c, int count){
  54.     int  i= r();   //random index 0-4
  55.     int  l=c-96;   //l is the base character index
  56.     int  f = ((l*5)-5)+i;  //f is the final index of the dictionary word
  57.     if(l<0){
  58.         printf("\n");
  59.         return;
  60.     }else{
  61.     printf("%s ", simpDict[f]);
  62.     if(count==5 || c <=0){
  63.         printf("\n");
  64.         count =0;
  65.         }
  66.     }
  67. }
  68.  
  69. int main(int argc, char ** argv){
  70.  srand(time(NULL));
  71.     if(argc !=2){
  72.         printf("Usage: %s <inputfile.txt>\n", argv[0]);
  73.         }
  74.     FILE *file1=fopen(argv[1], "r"); //file to decode
  75.    
  76.     int count = 0;
  77.    
  78.     if(file1==NULL ){
  79.         printf("Input Files ( %s ) Not Found\n", argv[1]);
  80.         return 0;
  81.         }
  82.        
  83.     char c;
  84.     while(c!=EOF){
  85.         c =fgetc(file1);
  86.         if(c == EOF){
  87.             break;
  88.             }
  89.         getNC(c, count);    
  90.         count ++;
  91.         }  
  92.         printf("\n");
  93.     return 0;
  94.     }
Add Comment
Please, Sign In to add comment