|
| 1 | +title: Encode share link |
| 2 | + |
| 3 | +# Various tests |
| 4 | + |
| 5 | +[Test1a (user: dave)](userpass1.md#IWRhdmU6bnVDbGVhcl9sdWxsYWJ5X3VudmVpbGVkX2c0cmxpYw)\ |
| 6 | +[Test1b (user: dave)](userpass1.md#!dave:nuClear_lullaby_unveiled_g4rlic) |
| 7 | + |
| 8 | +[Test2a (user: dave, go to anchor-6)](anchor.md#IWRhdmU6bnVDbGVhcl9sdWxsYWJ5X3VudmVpbGVkX2c0cmxpYw#anchor-6)\ |
| 9 | +[Test2b (user: dave, go to anchor-6)](anchor.md#!dave:nuClear_lullaby_unveiled_g4rlic#anchor-6) |
| 10 | + |
| 11 | +[Test3a (password: m00dy#augmented#Arsonist)](onlypasswords2.md#ITptMDBkeSNhdWdtZW50ZWQjQXJzb25pc3Q)\ |
| 12 | +[Test3b (password: SpotChestOilCycle22)](onlypasswords2.md#!SpotChestOilCycle22) |
| 13 | + |
| 14 | +[Test4a (obfuscate: Kriechtier hau ab!)](obfuscate.md#ITpLcmllY2h0aWVyIGhhdSBhYiE)\ |
| 15 | +[Test4b (obfuscate: Kriechtier hau ab!)](obfuscate.md#!Kriechtier%20hau%20ab!) |
| 16 | + |
| 17 | +# Create share link |
| 18 | + |
| 19 | +<div class="w3-row-padding" style="padding-left: 0px;"> |
| 20 | + <div class="w3-third"> |
| 21 | + <label for="share-user">username</label> |
| 22 | + <input class="w3-input w3-border w3-hover-theme w3-theme-l1" name="share-user" id="share-user" type="text" value="dave" onchange="genB64Url();"> |
| 23 | + </div> |
| 24 | + <div class="w3-third"> |
| 25 | + <label for="share-pass">password</label> |
| 26 | + <input class="w3-input w3-border w3-hover-theme w3-theme-l1" name="share-pass" id="share-pass" type="text" value="nuClear_lullaby_unveiled_g4rlic" onchange="genB64Url();"> |
| 27 | + </div> |
| 28 | +</div> |
| 29 | + |
| 30 | +<div class="w3-row-padding w3-margin-top" style="padding-left: 0px;"> |
| 31 | + <div class="w3-twothird"> |
| 32 | + <label for="share-output">output</label> |
| 33 | + <input class="w3-input w3-border w3-hover-theme w3-theme-l1" name="share-output" id="share-output" type="text" onchange="decB64Url();"> |
| 34 | + <div id="output-length"></div> |
| 35 | + </div> |
| 36 | +</div> |
| 37 | + |
| 38 | +<div class="w3-row-padding w3-margin-top" style="padding-left: 0px;"> |
| 39 | + <div class="w3-twothird"> |
| 40 | + <label for="share-decode">decoded</label> |
| 41 | + <code name="share-decode" id="share-decode" type="text"></code> |
| 42 | + <div id="decode-length"></div> |
| 43 | + </div> |
| 44 | +</div> |
| 45 | + |
| 46 | +<script> |
| 47 | +var share_user = document.getElementById('share-user'); |
| 48 | +var share_pass = document.getElementById('share-pass'); |
| 49 | +var share_output = document.getElementById('share-output'); |
| 50 | +var share_decode = document.getElementById('share-decode'); |
| 51 | +var share_url = document.getElementById('share-url'); |
| 52 | +var output_length = document.getElementById('output-length'); |
| 53 | +var decode_length = document.getElementById('decode-length'); |
| 54 | +var url_length = document.getElementById('url-length'); |
| 55 | + |
| 56 | + |
| 57 | +//https://developer.mozilla.org/en-US/docs/Glossary/Base64#the_unicode_problem |
| 58 | +function base64ToBytes(base64) { |
| 59 | + const binString = atob(base64); |
| 60 | + return Uint8Array.from(binString, (m) => m.codePointAt(0)); |
| 61 | +} |
| 62 | + |
| 63 | +function bytesToBase64(bytes) { |
| 64 | + const binString = Array.from(bytes, (x) => String.fromCodePoint(x)).join(""); |
| 65 | + return btoa(binString); |
| 66 | +} |
| 67 | + |
| 68 | +function base64url_decode(input) { |
| 69 | + try { |
| 70 | + return new TextDecoder().decode(base64ToBytes(input.replace(/-/g, '+').replace(/_/g, '/'))); |
| 71 | + } |
| 72 | + catch (err) { |
| 73 | + return "!ERROR!"; |
| 74 | + } |
| 75 | +} |
| 76 | +function base64url_encode(input) { |
| 77 | + try { |
| 78 | + return bytesToBase64(new TextEncoder().encode(input)).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, ''); |
| 79 | + } |
| 80 | + catch (err) { |
| 81 | + return "!ERROR!"; |
| 82 | + } |
| 83 | +} |
| 84 | + |
| 85 | + |
| 86 | +function genB64Url() { |
| 87 | + const str = "!" + share_user.value + ":" + share_pass.value; |
| 88 | + let encstr = base64url_encode(str); |
| 89 | + share_output.value = '#' + encstr; |
| 90 | + decB64Url() |
| 91 | +} |
| 92 | + |
| 93 | +function decB64Url() { |
| 94 | + let encstr = share_output.value.substr(1); |
| 95 | + output_length.innerHTML = "length: " + encstr.length; |
| 96 | + let decstr = base64url_decode(encstr) |
| 97 | + share_decode.textContent = decstr; |
| 98 | + decode_length.innerHTML = "length: " + decstr.length; |
| 99 | +} |
| 100 | +genB64Url(); |
| 101 | + |
| 102 | +</script> |
| 103 | + |
| 104 | +# Sharelinks output |
| 105 | + |
| 106 | +sharelinks.txt |
| 107 | + |
| 108 | +``` |
| 109 | +{% include "../../sharelinks.txt" %} |
| 110 | +``` |
0 commit comments