c++ - ASCII country at war homework -


i have make converter take message :mmz\dxzmx]zpgy convert corresponding ascii number, use formula

if(originalchar+key > 126)     encryptedchar = 32 + ((orgiginalchar + key) - 127); else     encryptedchar = (orginalchar + key); 

the key in problem number between 1 100 have try formula every possible key till message makes sense made.

so can tell me i'm doing wrong or point me in right direction

#include <iostream> #include <cstdlib>  using namespace std;  void converter(char originalchar, int key);  int main() {     char originalchar[16] = ":mmz\\dxzmx]zpgy";     int key;      converter((int)originalchar, key);      system("pause");     return 0;  }  void converter()(char originalchar, int key) {     char answer;      (key = 0; key <= 100; key++)     {         if (originalchar - key < 32)         {             answer = (((originalchar - key) + 127) - 32);         }         else         {             answer = (originalchar - key);         }         cout << (char)answer;     } } 

one of problems casting entire array of characters single integer. tough thing since integer cannot contain 16 characters.
see: converter((int)originalchar, key);

also, converter function supposed do?
variable name says passing original character (before encryption), however, don't have original character, encrypted character.

why passing copy of key value overwriting in for loop? did want pass reference?

edit 1:
perhaps want put call converter inside for loop:

for (unsigned int = 0; < sizeof(originalchar); ++i) {     converter(originalchar[i], key); } 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -