@BlueBowser/

CTF: reverse crypto

C++

w k h -j p e k -k u -w k h -a s v h -a q v k o f n s b s u u s f -

fork
loading
Files
  • main.cpp
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <iostream>
#include <string>
using namespace std;

/*
chipher text: 
w k h -j p e k -k u -w k h -a s v h -a q v k o f n s b s u u s f -
*/
string shift(string in){
  string re;
  //s is the length of in
  int s = in.length();
  //for i =  0, i less than length of in, increment by 1
  for (int i = 0; i <= ((in.length())-1); i++){
    //set asci to the number of ascii character
    int asci = in[i];
    //if length of ascii + length is less than or equal to 122 (z)
    if ((s+asci)<=122){
      //fill re position with the string of ascii + its length
      re[i] = (asci+s);
      } else {
        //fill re with (ascii + its legth) - 26
        re[i] = ((asci+s)-26);
      }
    
    cout << re[i] << " ";
  }
  cout << "-";
  //everything is shifted over 1 character( a > b)
  return re;
}

int main() {
  long l;
  cout << "What is the word count of your plain text? \n";
  cin >> l;

  cout << "\n Enter a " << l << " word long message.  \n (permited charset is lowercase letters and spaces) \n";
  string pt[l];
  for (long i = 0; i<=(l-1); i++){
    cin >> pt[i];
  }
  cout << "\n [START]" << endl;
  string re[l];
  for (long i = 0; i<=(l-1); i++){
    shift(pt[i]);
  }
   cout << "\n [STOP]";
  return 0;
  
  

}