Last active
February 5, 2022 04:58
-
-
Save tenderlove/6618a83cec6e28b4880ca804b375bd33 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# Smart Health Card decoder | |
# This decodes the SHC url thing that is stored in smart health card QR codes | |
str = DATA.readline | |
require "base64" | |
require "zlib" | |
require "json" | |
require "pp" | |
payload = str.delete_prefix("shc:/").scan(/\d\d/).map { |x| (x.to_i + 45).chr }.join | |
payload = payload.split(".").map { |x| | |
pad = x.bytesize % 4 | |
Base64.urlsafe_decode64("#{x}#{pad == 0 ? nil : '=' * (4-pad)}") | |
} | |
pp JSON.load payload.first | |
zlib = Zlib::Inflate.new(-15) | |
pp JSON.load zlib.inflate payload[1] | |
__END__ | |
shc:/1234... | |
Decode your health card QR code and paste the shc "URL" above |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
present code attempted to add
====
as a padding whenx.bytesize % 4
is zero...