Gpt's code for finding the maximum of { p( c(a,key) ) } where p is english scoring function and c is xor decryption function. function singleByteXOR(hexString) { const hexToBytes = (hex) => new Uint8Array(hex.match(/.{1,2}/g).map(byte => parseInt(byte, 16))); const xorWithKey = (bytes, key) => bytes.map(byte => byte ^ key); const frequencyScore = (text) => { // A simple scoring function based on the frequency of common English letters const frequencies = { 'a': 0.08167, 'b': 0.01492, 'c': 0.02782, 'd': 0.04253, 'e': 0.12702, 'f': 0.02228, 'g': 0.02015, 'h': 0.06094, 'i': 0.06966, 'j': 0.00153, 'k': 0.00772, 'l': 0.04025, 'm': 0.02406, 'n': 0.06749, 'o': 0.07507, 'p': 0.01929, 'q': 0.00095, 'r': 0.05987, 's': 0.06327, 't': 0.09056, 'u': 0.02758, 'v': 0.00978, 'w': 0.02360, 'x': 0.00150, 'y': 0.01974, 'z': 0.00074, ' ': 0.13000 // Adding space for better scoring of English text }; const score = text.toLowerCase().split('') .map(char => frequencies[char] || 0) .reduce((total, freq) => total + freq, 0); return score; }; const ciphertext = hexToBytes(hexString); let bestScore = 0; let bestKey = 0; let bestPlaintext = ''; for (let key = 0; key <= 255; key++) { const plaintextBytes = xorWithKey(ciphertext, key); const plaintext = String.fromCharCode(...plaintextBytes); const score = frequencyScore(plaintext); if (score > bestScore) { bestScore = score; bestKey = key; bestPlaintext = plaintext; } } return { key: bestKey, plaintext: bestPlaintext }; } const hexString = '1b37373331363f78151b7f2b783431333d78397828372d363c78373e783a393b3736'; const result = singleByteXOR(hexString); console.log('Key:', result.key); console.log('Plaintext:', result.plaintext); Another task is find the sum of multiples in a 1..n ranges which are 3 5 7. Good spotting of progression formula. x1+x2+xn = x(1+xn)/2; find sums divisible by 3 5 7 substract the progressions of 15 21 35 105. function sumDivisibleBy(n, divisor) { const p = Math.floor(n / divisor); return divisor * (p * (p + 1)) / 2; } function sumDivisibleByThreeFiveSeven(n) { return ( sumDivisibleBy(n, 3) + sumDivisibleBy(n, 5) + sumDivisibleBy(n, 7) - sumDivisibleBy(n, 3 * 5) - sumDivisibleBy(n, 3 * 7) - sumDivisibleBy(n, 5 * 7) + sumDivisibleBy(n, 3 * 5 * 7) ); } // Test the function const n = 100; console.log(sumDivisibleByThreeFiveSeven(n)); // Output: 1935