diff --git a/set1/challenge3_xor_cipher/src/main.zig b/set1/challenge3_xor_cipher/src/main.zig index 53ea31c..a3ff6d4 100644 --- a/set1/challenge3_xor_cipher/src/main.zig +++ b/set1/challenge3_xor_cipher/src/main.zig @@ -52,7 +52,7 @@ pub fn main() anyerror!void { var bestkey: u8 = 0; var bestscore: u32 = 0; var key: u8 = 0; - while (true) { + while (true) : (key += 1) { decrypt(plaintext, ciphertext, key); const s = score(plaintext); if (s > bestscore) { @@ -60,7 +60,7 @@ pub fn main() anyerror!void { bestscore = s; } key +%= 1; - if (key == 0) { + if (key == std.math.maxInt(u8)) { break; } } diff --git a/set1/challenge4_detect_xor/src/main.zig b/set1/challenge4_detect_xor/src/main.zig index a7dd342..ff7ec4b 100644 --- a/set1/challenge4_detect_xor/src/main.zig +++ b/set1/challenge4_detect_xor/src/main.zig @@ -54,7 +54,7 @@ pub fn main() anyerror!void { var plaintext = try allocator.alloc(u8, ciphertext.len); defer allocator.free(plaintext); var key: u8 = 0; - while (true) { + while (true) : (key += 1) { decrypt(plaintext, ciphertext, key); const s = score(plaintext); if (s > bestscore) { @@ -62,8 +62,7 @@ pub fn main() anyerror!void { std.mem.copy(u8, bestplaintext.items, plaintext); bestscore = s; } - key +%= 1; - if (key == 0) { + if (key == std.math.maxInt(u8)) { break; } }