File tree Expand file tree Collapse file tree 3 files changed +8
-5
lines changed Expand file tree Collapse file tree 3 files changed +8
-5
lines changed Original file line number Diff line number Diff line change 1
1
CXX =g++
2
2
CFLAGS =-I.
3
3
4
- baby_rev : baby_rev.c
4
+ baby_rev : baby_rev.cpp
5
5
$(CXX ) -o baby_rev baby_rev.cpp
6
6
7
7
clean :
Original file line number Diff line number Diff line change 1
1
#include < string>
2
2
#include < iostream>
3
+ #include < string_view>
3
4
4
- constexpr auto KEY = 42 ;
5
+ constexpr char KEY = 42 ;
6
+ constexpr std::string_view PHRASE_CIPHERTEXT = " ]I^LQREXu^]CIOuCYuDEEZW" ;
5
7
6
8
bool is_phrase_correct (std::string_view phrase)
7
9
{
8
- for (char c : phrase)
10
+ std::string ciphertext{phrase};
11
+ for (char & c : ciphertext)
9
12
{
10
- std::cout << static_cast < char >( c ^ KEY) << std::endl ;
13
+ c ^= KEY;
11
14
}
15
+ return ciphertext == PHRASE_CIPHERTEXT;
12
16
}
13
17
14
18
int main ()
15
19
{
16
-
17
20
std::string phrase;
18
21
std::cout << " What's the secret phrase?" << std::endl;
19
22
You can’t perform that action at this time.
0 commit comments