-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidityFunctions.cpp
More file actions
152 lines (135 loc) · 4.42 KB
/
Copy pathvalidityFunctions.cpp
File metadata and controls
152 lines (135 loc) · 4.42 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/**
* Description: header file for a static class that stores each of the validity functions for the challenges in each section of the Learn Mips app
* Authors: Matthew Ashton Knochel, Carter Dean, Abdulla Alnuaimi, Logan Luker, Aidan Sheehan
*/
#include "validityFunctions.h"
#include "Interpreter.h"
#include <iostream>
using namespace std;
bool ValidityFunctions::section1ValidityFunction(std::string code) {
try {
Interpreter interpreter1(code);
interpreter1.run();
return interpreter1.getV0() == 14;
} catch (string err) {
cout << "ERROR: " + err << endl;
return false;
}
}
bool ValidityFunctions::section2ValidityFunction(std::string code){
try {
unsigned int num = 3000;
int n = 8; // Number of least significant bits to isolate
unsigned int isolated = (num << (32 - n)) >> (32 - n);
Interpreter interpreter2(code);
interpreter2.run();
return interpreter2.getV0() == isolated;
} catch (string err) {
cout << "ERROR: " + err << endl;
}
}
bool ValidityFunctions::section3ValidityFunction(std::string code){
try {
Interpreter interpreter3(code);
string expectedString = "Jerry STOLE 32767 eggs on his spree!";
string outputString = interpreter3.run();
return expectedString == outputString;
} catch (string err) {
cout << "ERROR: " + err << endl;
return false;
}
}
bool ValidityFunctions::section4ValidityFunction(std::string code){
//5 + 5 + 5 + 5 + 5 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 = 93
try {
Interpreter interpreter4(code);
interpreter4.run();
cout << interpreter4.getV0() << endl;
return interpreter4.getV0() == 93;
} catch (string err) {
cout << "ERROR: " + err << endl;
return false;
}
}
bool ValidityFunctions::section5ValidityFunction(std::string code){
try {
Interpreter interpreter5(code);
interpreter5.run();
return interpreter5.getV0() == 12;
} catch (string err) {
cout << "ERROR: " + err <<endl;
return false;
}
}
bool ValidityFunctions::section6ValidityFunction(std::string code){
try {
Interpreter interpreter6(code);
interpreter6.run();
// mystring should be HELLOWORLD
optional<vector<uint8_t>> capitalized = interpreter6.getSymbol("myString", 10);
if (!capitalized.has_value())
throw ("No myString symbol found");
string actual = "HELLOWORLD";
for (int index = 0; index < 10; index++) {
if (actual.at(index) != capitalized.value().at(index)) {
return false;
}
}
} catch (string err) {
cout << "ERROR: " << err << endl;
return false;
}
return true;
}
/// XOR challenge
bool ValidityFunctions::section7ValidityFunction(std::string code){
try {
// v0 should contain 11, the length of the ciphertext
Interpreter interpreter7(code);
interpreter7.run();
if (interpreter7.getV0() != 11) {
return false;
}
optional<vector<uint8_t>> ciphertext = interpreter7.getSymbol("ciphertext", interpreter7.getV0());
if (!ciphertext.has_value()) {
return false;
}
uint8_t correctAns[11] = {0x04, 0x19, 0x00, 0x1c, 0x17, 0x0b, 0x0c, 0x19, 0x1b, 0x15, 0x05};
for (int i = 0; i < 11; i++) {
if (ciphertext.value().at(i) != correctAns[i]) {
return false;
}
}
} catch (string err) {
cout << "ERROR: " + err << endl;
}
return true;
}
bool ValidityFunctions::section8ValidityFunction(std::string code){
try {
Interpreter interpreter8(code);
interpreter8.run();
//$s1 contains 1532
return (interpreter8.getV1() == 1542) && (interpreter8.getV0() == 5432);
} catch (string err) {
cout << "ERROR: " + err <<endl;
return false;
}
}
bool ValidityFunctions::section9ValidityFunction(std::string code){
int tenthFibonacciValue = 55;
try {
Interpreter bonus1(code);
bonus1.run();
return bonus1.getV1() == tenthFibonacciValue;
} catch (string err){
cout << "ERROR: " << err << endl;
return false;
}
}
bool ValidityFunctions::section10ValidityFunction(std::string code){
return false;
}
bool ValidityFunctions::section11ValidityFunction(std::string code){
return false;
}