第四题我来个C语言版本的吧....
- #include <windows.h>
- #include <stdio.h>
- #include <stdint.h>
- #include <intrin.h>
- #include <stdbool.h>
- bool findSubset(UINT64* arr, int n, UINT64 target, UINT64* subset, int subsetSize, UINT64* hex)
- {
- if (target == 0){
- for (int i = 0; i < subsetSize; i++){
- hex[i] = subset[i];
- }
- return true;
- }
- if (n == 0 || target < 0){
- return false;
- }
- subset[subsetSize] = arr[n - 1];
- if (findSubset(arr, n - 1, target - arr[n - 1], subset, subsetSize + 1, hex)){
- return true;
- }
- return findSubset(arr, n - 1, target, subset, subsetSize, hex);
- }
- int main()
- {
- #define KEY_NUM (ARRAYSIZE(hexNumbers))
- UINT64 hexNumbers[] = {
- 0x99B5BD33, 0x5CBCDDC2, 0x740E795A, 0x465ED09E,
- 0x3C7DC5A, 0x2E97A4F1, 0x0B05264C, 0x1CFA7AE0,
- 0x0E8635A24, 0x0A39B4537, 0x78669AF8, 0x5F3C498E,
- 0x0D2402FF6, 0x0C6D80C6F, 0x0CF4FF6BC, 0x17505835
- };
- UINT64 target[] = {
- 0x88845B48, 0x17C22A857, 0x6E5E71CA, 0x0B35423DF,
- 0x127629D39, 0x10BDC0B57, 0x1D8DF8619, 0x0C57D3AB9,
- 0x14D09E112, 0x9FD5F6E0, 0x9C0E1A86, 0x13F29C8E6,
- 0x0CB1B4F8C, 0x6E5E71CA, 0x0E634C77E, 0x88845B48,
- 0x27FFA12C, 0x27FFA12C, 0x0C1B55E5F, 0x11E723C21,
- 0x9C0E1A86, 0x13F29C8E6, 0x16898E919, 0x0C57D3AB9,
- 0x9C0E1A86, 0x13F29C8E6, 0x9CF616BB
- };
- UINT64 subset[KEY_NUM];
- UINT64 hex[KEY_NUM];
- int s = 'f';
- printf("%c", s);
- for (int k = 0; k < ARRAYSIZE(target); ++k){
- memset(hex, 0, sizeof(hex));
- if (!findSubset(hexNumbers, KEY_NUM, target[k], subset, 0, hex)){
- printf("No subset found.\n");
- }
- int c = 0;
- for (int i = 0; i < KEY_NUM; ++i){
- for (int j = 0; j < KEY_NUM; ++j){
- if (hex[j] == 0)
- break;
- if (hex[j] == hexNumbers[i])
- c |= (1 << (i));
- }
- }
- //printf("[%x]", c);
- s = c - s;
- if (s < 0x20 || s >= 0x7f)
- printf("\n code error %x\n", s);
- printf("%c", s);
- }
- return 0;
- }
复制代码
|