Skip to content

Instantly share code, notes, and snippets.

@brunerd
Created August 24, 2021 04:32
Show Gist options
  • Save brunerd/30346142b1152b2915f638c3152441e6 to your computer and use it in GitHub Desktop.
Save brunerd/30346142b1152b2915f638c3152441e6 to your computer and use it in GitHub Desktop.
Encode password for macOS /etc/kcpassword (does not handle blank passwords)
#!/bin/bash
function kcpasswordEncode_perl {
local PASSWORD="${1}";
#one-liner variation of Gavin Brock's kcpassword.pl
perl -ne 'sub kcpassword_xor { my ($pass)=@_; my @key=qw( 125 137 82 35 210 188 221 234 163 185 31 ); my $key=pack "C*", @key; my $key_len=length $key; for (my $n=0; $n<length($pass); $n+=$key_len) { substr($pass,$n,$key_len) ^= $key; }; return $pass; }; $userinput = $_; chomp ($userinput); print(kcpassword_xor($userinput));' <<< "${PASSWORD}"
}
kcpasswordEncode_perl "${1}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment