test.c 714 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #include <stdio.h>
  2. #include <stdint.h>
  3. uint8_t SECRET_KEY = 0x5f;
  4. uint8_t XOR(uint8_t a, uint8_t b) {
  5. return a ^ b;
  6. }
  7. uint8_t encrypt(uint8_t input) {
  8. uint8_t tmp = input;
  9. for(int i=0; i < 7; i++) {
  10. tmp = XOR(tmp, SECRET_KEY);
  11. }
  12. return tmp;
  13. }
  14. void test_masked() {
  15. uint8_t mask = 0xFF;
  16. uint8_t pt = 0xBB;
  17. uint8_t masked_pt = XOR(mask, pt);
  18. uint8_t masked_ct = encrypt(masked_pt);
  19. uint8_t ct = XOR(masked_ct, mask);
  20. printf("Encrypted to: 0x%02x\n", ct);
  21. }
  22. void test_normal() {
  23. uint8_t pt = 0xBB;
  24. uint8_t ct = encrypt(pt);
  25. printf("Encrypted to: 0x%02x\n", ct);
  26. }
  27. int main() {
  28. test_normal();
  29. test_masked();
  30. return 0;
  31. }