Skip to content

Instantly share code, notes, and snippets.

@Saturate
Last active October 27, 2023 19:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Saturate/306f03c7a884b9e8db806f7da1575b1b to your computer and use it in GitHub Desktop.
Save Saturate/306f03c7a884b9e8db806f7da1575b1b to your computer and use it in GitHub Desktop.
const key = [8, 131, 214, 191, 186, 15, 133, 27, 56, 78, 231, 188];
const password_enc = "5bf6a6dac85ce0784a7d93ec69f0a5c88a7de13a";
const encrypt = (bytes, key) => {
for (var i = 0; i < bytes.length; i++) {
bytes[i] = bytes[i] ^ key[i % key.length];
}
return bytes;
};
const check_password = (password) => {
const bytes = [];
for (let i = 0; i < password.length; i++) {
bytes.push(password.charCodeAt(i));
}
encrypt(bytes, key);
let s = "";
for (var i = 0; i < bytes.length; i++) {
s += bytes[i].toString(16);
}
return s == password_enc;
};
// Crack the code, here:
const encodedBytes = password_enc
.match(/.{1,2}/g)
.map((byte) => parseInt(byte, 16));
console.log('encodedBytes', encodedBytes);
const decrypt = (bytes, key) => {
for (var i = 0; i < bytes.length; i++) {
bytes[i] = bytes[i] ^ key[i % key.length];
}
return bytes;
};
console.log(
decrypt(encodedBytes, key).reduce(
(message, byte) => message + String.fromCharCode(byte),
""
)
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment