Null Cypher

Oct 15, 2015 at 6:08am
I want decode a cipher like

AAAMAAAeAAAeAAAtAAA AAAMAAAeAAA AAAIAAAnAAA AAASAAAaAAAiAAAnAAAtAAA AAALAAAoAAAuAAAiAAAsAAA

...and try only printing every fourth letter, you see:

Meet Me In Saint Louis

this is my code.However it doesn't work well
<
#include <string>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iomanip>

using namespace std;


int main (int argc, char *argv[], char **env)
{
int a, count =4 ;
a = + count ;
char d;

do
{for(int i=1; i<=count; i++)
cout.put(a = + count);
cin.ignore(a);
d=cin.get();
cout.put(d);

} while (!cin.eof());

}
>
Last edited on Oct 15, 2015 at 6:08am
Oct 15, 2015 at 8:16am
Use the modulo operator (Arithmetic operators):

http://www.cplusplus.com/doc/tutorial/operators/

Every fourth would be like this: if((i % 4) == 0) ...

Furthermore: The loop would be simplier like that: for(int i = 1; cin >> d; i++)
Oct 17, 2015 at 4:41am
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
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iomanip>
using namespace std;

int main(int argc, char *argv[])
{
    int a, c, count = atoi(argv[2]);
    srand(time(NULL));
    c = rand() % 94 ;
    c += 32 ;
    a = + count;
    char b;
    char d;

        if(argv[1] == 'e') // encryption
        {
            do
            {for (int i = 1; i <= count; i++)
            cout.put( c = (32 + rand() % 94) ) ;

            b = cin.get();
            cout.put(b);
            } while (!cin.eof());
        }
        else if (argv[1] == 'd') // decryption
        {
            {for(int i = 1; cin>> d; i++)
                if(( i % count) == 0)
                {
                    cout.put(a=+count);
                    d=cin.get();
                    cout.put(d);
                }
                    return 0 ;
                } while (!cin.eof());
                    return 0;
        }
        else (argv[1] != 'e' | 'd')
            {
                cout << " program can not work! "<< endl ;
            }
        return 0;
}


this is my finally code for decryption and encryption of Null Cypher. Howerver, I think I wrong somewhere. Could you please help me fix it. I want the Command Line will be
a.out e 3 - for encryption.
a.out d 3 for decryption.
Oct 17, 2015 at 6:35am
closed account (48T7M4Gy)
Why do you think you are wrong?
Oct 17, 2015 at 6:44am
Because I can compile it in in putty. it said: "ISO c++ forbids comparison between pointer and integer". and in decryption, debut does not complete. I am just learning the program class. Might you help me?
Oct 17, 2015 at 7:10am
closed account (48T7M4Gy)
 In function 'int main(int, char**)': 
18:23: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
28:29: error: ISO C++ forbids comparison between pointer and integer [-fpermissive] 
41:26: error: ISO C++ forbids comparison between pointer and integer [-fpermissive] 
41:23: warning: suggest parentheses around comparison in operand of '|' [-Wparentheses] 42:13: error: expected ';' before '{' token 
44:13: warning: second operand of conditional expression has no effect [-Wunused-value] 44:13: warning: third operand of conditional expression has no effect [-Wunused-value]


You should learn to read the error messages and include them with your questions. I'll do it for you this time.

You need to dereference the pointers in each of the lines mentioned 18, 28 and 41. Look it up.

Line 41 is wrong e|d is not the way to do what you are trying to do. And I think you are missing an 'if'.


Oct 17, 2015 at 7:27am
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>
#include <string>
using std::cin;
using std::cout;
using std::endl;
using std::string;

int main()
{
string str;
getline(cin, str);
for (int i = 3; i < str.length(); i+=4) cout << str[i];
cout << endl;
}
Oct 17, 2015 at 8:45am
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
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <string>
using namespace std;

int main(int argc, char *argv[])
{
    int a, c, count = atoi(argv[2]);
    srand(time(NULL));
    c = rand() % 94 ;
    c += 32 ;
    a = + count;
    char b;
    char d;

        if( *argv[1] = 'e') // encryption
        {
            do
            {for (int i = 1; i <= count; i++)
            cout.put( c = (32 + rand() % 94) ) ;

            b = cin.get();
            cout.put(b);
            } while (!cin.eof());
        }
        else if ( *argv[1] = 'd') // decryption
        {
            {for(int i = 1; cin>> d; i++)
                if(( i % count) == 0)
                {
                    cout.put(a=+count);
                    d=cin.get();
                    cout.put(d);
                }
                    return 0 ;
                } while (!cin.eof());
                    return 0;
        }
        else ;
            {
                cout << " program can not work! "<< endl ;
            }
        return 0;
}


how about now?
Oct 17, 2015 at 10:27am
closed account (48T7M4Gy)
how about now?

Well, it looks like the dereferencing breakthrough is made. Presumably no more errors.

Neater way of getting over e or d not being selected too.

Line 42 has a problem at its end though.

I haven't run your code but I think you must be very close.
Topic archived. No new replies allowed.