-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathFourBitTwoDisclosureDeviceUnlocker.java
More file actions
63 lines (51 loc) · 2.21 KB
/
FourBitTwoDisclosureDeviceUnlocker.java
File metadata and controls
63 lines (51 loc) · 2.21 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
/**
* Solution development for 4-bit/2-disclosure device.
*
* @version API: 4.1.4
* <br>
* Source code: 4.1.7
* @author Dr. Jody Paul: API specification,
* <br>
* Heather DeMarco, Jonathan Grant: Source code matching API
*
* @see <a href = "http://jodypaul.com/cs/sweprin/deviceProj/projectDescription.html"> Project Description </a>
*
*/
public class FourBitTwoDisclosureDeviceUnlocker extends DeviceUnlocker {
/**
*Unlocks a resource controlled by a 4-bit/2-disclosure device. Behavior is unspecified if parameter is not a reference to a valid 4-bit/2-disclosure device.
*
* @param dev - the device controlling the resource to unlock; must be a 4-bit device with 2 peek/poke bits.
* @return true if the resource is successfully unlocked (all bits are now identical); false otherwise
*/
public static boolean unlock(Device dev){
//Set up variables
boolean forSpin;
CharSequence forPeek = "??--";
CharSequence forPoke = "TT--";
CharSequence fromPeek;
// Reset the trace
FourBitTwoDisclosureDeviceUnlocker.log(null);
// We're staring the unlock
FourBitTwoDisclosureDeviceUnlocker.log("Unlock start");
//The loop is set to run 100 times before halting.
for(int i=0; i <= 100; i++) {
forSpin = dev.spin();
//If true, loop is exited
if (forSpin) {
FourBitTwoDisclosureDeviceUnlocker.log("Spin: unlocked");
FourBitTwoDisclosureDeviceUnlocker.log("Unlock SUCCESS");
return true;
}
FourBitTwoDisclosureDeviceUnlocker.log("Spin: locked");
FourBitTwoDisclosureDeviceUnlocker.log("Peek pattern: " + forPeek.toString());
fromPeek = dev.peek(forPeek);
FourBitTwoDisclosureDeviceUnlocker.log("Peek result: " + fromPeek.toString());
FourBitTwoDisclosureDeviceUnlocker.log("Poke: " + forPoke.toString());
dev.poke(forPoke);
FourBitTwoDisclosureDeviceUnlocker.log(dev.toString());
}
FourBitTwoDisclosureDeviceUnlocker.log("Unlock FAILED");
return false;
}
}