Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# Ported from https://github.com/timsutton/osx-vm-templates/blob/master/scripts/support/set_kcpassword.py
key = [125, 137, 82, 35, 210, 188, 221, 234, 163, 185, 31]
key_len = key.length
newpasswd = []
passwd.each_char do |char|
newpasswd << char.ord
end
r = newpasswd.length % key_len
# pad passwd length out to an even multiple of key length
newpasswd += [0] * (key_len - r) if r > 0
(0..newpasswd.length - 1).step(key.length) do |n|
ki = 0
(0..(n + key.length..newpasswd.length).min).each do |j|
newpasswd[j] = newpasswd[j] ^ key[ki]
ki += 1
end
end
realpasswd = []
(newpasswd - [false]).each do |char|
realpasswd << char.chr
end
realpasswd.join('')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment