Created
July 22, 2016 13:36
-
-
Save nmcspadden/7d01ef840836b66582cae63878540002 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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