I-Base64 Encoding
Ngesixhobo se-Encoding ye-Base64, ungabhala ngokuntsonkothileyo umbhalo owufakayo ngendlela ye-Base64. Ukuba uyanqwenela, unokwenza ikhowudi yekhowudi ye-Base64 efihliweyo ngesixhobo se-Base64 Decode.
Yintoni i-Base64 Encoding?
I-Base64 i-encoding yinkqubo yokufaka ikhowudi evumela ukuba idatha yokubini ithuthwe kwiindawo ezisebenzisa kuphela ezinye iikhowudi zoonobumba ezithintelweyo (indalo engqongileyo apho ingezizo zonke iikhowudi zoonobumba ezinokusetyenziswa, njenge xml, html, script, izicelo zemiyalezo ekhawulezileyo). Inani labalinganiswa kolu dweliso ngama-64, kwaye inani lama-64 kwigama elithi Base64 lisuka apha.
Kutheni Usebenzisa i-Base64 Encoding?
Imfuno ye-encoding ye-Base64 ivela kwiingxaki ezivela xa imidiya ihanjiswa kwifomathi yokubini eluhlaza kwiinkqubo ezisekelwe kwisicatshulwa. Ngenxa yokuba iinkqubo ezisekelwe kumbhalo (ezifana ne-imeyile) zitolika idata yokubini njengoluhlu olubanzi lwabalinganiswa, kuquka abalinganiswa abakhethekileyo bomyalelo, uninzi lwedatha yokubini egqithiselwa kumbindi wodluliselo itolikwa gwenxa zezi nkqubo kwaye ilahleka okanye yonakaliswe kuthumelo. inkqubo.
Enye indlela yokufaka ikhowudi yedatha yokubini ngendlela enqanda iingxaki ezinjalo zothumelo kukuthumela njengesicatshulwa esicacileyo se-ASCII kwifomathi ekhowudiweyo ye-Base64. Le yenye yeendlela ezisetyenziswa ngumgangatho we MIME ukuthumela idatha ngaphandle kokubhaliweyo okungenanto. Iilwimi ezininzi zeprogram, ezifana ne-PHP kunye ne-Javascript, zibandakanya i-Base64 ye-encoding kunye ne-decoding imisebenzi yokutolika idatha ehanjiswe kusetyenziswa i-Base64 encoding.
I-Base64 Encoding Logic
Kwi-encoding ye-Base64, i-3 * 8 bits = i-24 bits yedatha equkethe ii-bytes ezi-3 zihlulwe zibe ngamaqela ama-4 eebhithi ezi-6. Iimpawu ezihambelana nexabiso lokugqibela phakathi kwe- [0-64] yala maqela angama-4 amasuntswana ama-6 adityaniswa ukusuka kwitheyibhile ye-Base64 ukuya kwikhowudi. Inani loonobumba abafunyenwe ngenxa ye-Base64 encoding kufuneka ibe yi-multiple of 4. Idatha ekhowudiweyo engeyiyo i-multiple ye-4 ayisebenzi idatha ye-Base64. Xa ukufakwa kweekhowudi kunye ne-algorithm ye-Base64, xa i-encoding igqityiwe, ukuba ubude bedatha abuyi-multiple ye-4, "=" (elinganayo) uphawu longezwa ekupheleni kwe-encoding de ibe yi-multiple ye-4. Umzekelo, ukuba sine-10-character Base64 encoded data njengesiphumo sofakelo lwekhowudi, ezimbini "==" kufuneka zongezwe ekupheleni.
I-Base64 Encoding Umzekelo
Umzekelo, thatha amanani amathathu e-ASCII 155, 162 kunye no-233. La manani mathathu enza i-binary stream ye-100110111010001011101001. Ifayile yokubini efana nomfanekiso iqulathe umjelo wokubini osebenza kumashumi okanye amakhulu amawaka eqanda kunye nezinye. I-encoder ye-Base64 iqala ngokwahlula i-binary stream ibe ngamaqela abalinganiswa abathandathu: 100110 111010 001011 101001. Nganye kula maqela aguqulelwe kumanani 38, 58, 11, kunye nama-41. Umjelo wokubini wamagama amathandathu uguqulwa phakathi kokubini (okanye okusisiseko). 2) ukuya kwidesimali (isiseko-10) abasebenzi ngokuphinda-phinda ixabiso ngalinye elimelwe ngu-1 kuluhlu lokubini ngesikwere sendawo. Ukuqala ukusuka ekunene ukuya ekhohlo kwaye ukusuka ku-zero, amaxabiso kumjelo wokubini umele 2^0, ngoko 2^1, ngoko 2^2, ngoko 2^3, ngoko 2^4, ngoko 2^ 5.
Nantsi enye indlela yokuyijonga. Ukuqala ukusuka ekhohlo, indawo nganye ixabisa u-1, 2, 4, 8, 16 no-32. Ukuba isithuba sinenombolo yokubini 1, wongeza elo xabiso; ukuba i-slot ino-0, ulahlekile. Uluhlu lweBhinary 100110 lujika ku-38: 0 * 2 ^ 01 + 1 * 2 ^ 1 + 1 * 2 ^ 2 + 0 * 2 ^ 3 + 0 * 2 ^ 4 + 1 * 2 ^ 5 = 0 + 2 decimal + 4 + 0 + 0 + 32. I-Base64 encoding ithatha lo mtya wokubini kwaye iyahlulahlule ibe yi-6-bit values 38, 58, 11 kunye ne-41. Ekugqibeleni, la manani aguqulelwa kwiimpawu ze-ASCII usebenzisa i-Base64 encoding table.