Skip to content

Commit 3f01310

Browse files
committed
Finish baby rev example
1 parent 20c525f commit 3f01310

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

baby_rev/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
CXX=g++
22
CFLAGS=-I.
33

4-
baby_rev: baby_rev.c
4+
baby_rev: baby_rev.cpp
55
$(CXX) -o baby_rev baby_rev.cpp
66

77
clean:

baby_rev/baby_rev

29.5 KB
Binary file not shown.

baby_rev/password.cpp renamed to baby_rev/baby_rev.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
#include <string>
22
#include <iostream>
3+
#include <string_view>
34

4-
constexpr auto KEY = 42;
5+
constexpr char KEY = 42;
6+
constexpr std::string_view PHRASE_CIPHERTEXT = "]I^LQREXu^]CIOuCYuDEEZW";
57

68
bool is_phrase_correct(std::string_view phrase)
79
{
8-
for (char c : phrase)
10+
std::string ciphertext{phrase};
11+
for (char& c : ciphertext)
912
{
10-
std::cout << static_cast<char>(c ^ KEY) << std::endl;
13+
c ^= KEY;
1114
}
15+
return ciphertext == PHRASE_CIPHERTEXT;
1216
}
1317

1418
int main()
1519
{
16-
1720
std::string phrase;
1821
std::cout << "What's the secret phrase?" << std::endl;
1922

0 commit comments

Comments
 (0)