I-Base64 Encoding

Ngethuluzi Lokufaka Ikhodi Le-Base64, ungakwazi ukubethela umbhalo owufakayo ngendlela ye-Base64. Uma uthanda, ungakwazi ukukhipha ikhodi ye-Base64 ebethelwe ngethuluzi le-Base64 Decode.

Yini i-Base64 Encoding?

I-Base64 Encoding iwuhlelo lombhalo wekhodi oluvumela idatha kanambambili ukuthi ithuthwe ezindaweni ezisebenzisa kuphela ezinye izinhlobo zombhalo wekhodi zezinhlamvu ezikhawulelwe (izindawo lapho okungewona wonke amakhodi ezinhlamvu angasetshenziswa, njenge-xml, html, script, izinhlelo zokusebenza zemiyalezo esheshayo). Inombolo yezinhlamvu kulolu hlelo ngu-64, futhi inombolo engu-64 egameni elithi Base64 isuka lapha.

Kungani Usebenzisa Umbhalo Wekhodi We-Base64?

Isidingo sombhalo wekhodi we-Base64 sisukela ezinkingeni eziphakama lapho imidiya idluliswa ngefomethi kanambambili eluhlaza kumasistimu asekelwe emibhalweni. Ngenxa yokuthi amasistimu asekelwe emibhalweni (njenge-e-mail) ahumusha idatha kanambambili njengezinhlobonhlobo zezinhlamvu, okuhlanganisa nezinhlamvu ezikhethekile zomyalo, iningi ledatha kanambambili edluliselwa endaweni yokudlulisa ichazwa kabi yilezi zinhlelo futhi iyalahleka noma yonakaliswe ekudluliselweni kwedatha. inqubo.

Enye indlela yombhalo wekhodi idatha enjalo kanambambili ngendlela egwema izinkinga ezinjalo zokudlulisela iwukukuthumela njengombhalo ongenalutho we-ASCII ngefomethi yekhodi ye-Base64. Lena enye yezindlela ezisetshenziswa izinga le-MIME ukuthumela idatha ngaphandle kombhalo ongenalutho. Izilimi eziningi zokuhlela, ezifana ne-PHP ne-Javascript, zifaka phakathi umsebenzi wombhalo wekhodi we-Base64 nowokuchaza ukuhumusha idatha edluliswa kusetshenziswa umbhalo we-Base64.

I-Base64 Encoding Logic

Kumbhalo wekhodi we-Base64, amabhithi angu-3 * 8 = amabhithi angu-24 edatha ahlanganisa amabhayithi angu-3 ahlukaniswe ngamaqembu angu-4 wamabhithi angu-6. Izinhlamvu ezihambisana namanani edesimali phakathi kuka-[0-64] kulawa maqembu angu-4 6-bit zifaniswa ukusuka kuthebula le-Base64 ukuze kufakwe ikhodi. Inombolo yezinhlamvu ezitholwe ngenxa yombhalo wekhodi we-Base64 kufanele ibe ukuphindaphinda kokungu-4. Idatha efakwe ikhodi engeyona impinda yoku-4 akuyona idatha ye-Base64 evumelekile. Uma kufakwa ikhodi nge-algorithm ye-Base64, lapho umbhalo wekhodi usuqedile, uma ubude bedatha bungaphindaphinda u-4, uhlamvu "=" (olulinganayo) luyengezwa ekupheleni kombhalo wekhodi kuze kube ukuphindaphinda kuka-4. Isibonelo, uma sinedatha efakwe ikhodi ye-Base64 enezinhlamvu ezingu-10 njengomphumela wombhalo wekhodi, ezimbili "==" kufanele zengezwe ekugcineni.

Isibonelo Sokufaka Ikhodi se-Base64

Isibonelo, thatha izinombolo ezintathu ze-ASCII u-155, 162 kanye no-233. Lezi zinombolo ezintathu zakha ukusakazwa kanambambili kokuthi 100110111010001011101001. Ifayela kanambambili elifana nesithombe liqukethe umfudlana onambambili osebenzela amashumi noma amakhulu ezinkulungwane zoziro kanye nowodwa. Isishumeki se-Base64 siqala ngokuhlukanisa ukusakaza kanambambili kube amaqembu ezinhlamvu eziyisithupha: 100110 111010 001011 101001. Ngayinye yalawa maqembu ihunyushwa izinombolo 38, 58, 11, kanye no-41. Ukusakaza kanambambili kwezinhlamvu eziyisithupha kuguqulwa phakathi kanambambili (noma okuyisisekelo). 2) kuya kuzinhlamvu zedesimali (isisekelo-10) ngokufaka isikwele senani ngalinye elimelwe ngu-1 kuhlu lwezinombolo ezimbili ngesikwele sendawo. Kusukela kwesokudla kuya kwesokunxele bese iqala kuziro, amanani emfudlaneni kanambambili amele 2^0, bese 2^1, bese 2^2, bese 2^3, bese 2^4, bese 2^ 5.

Nansi enye indlela yokuyibuka. Kusukela kwesobunxele, isikhundla ngasinye sibiza u-1, 2, 4, 8, 16 kanye no-32. Uma i-slot inenombolo kanambambili 1, wengeza lelo nani; uma i-slot ino-0, ulahlekile. Uhlu kanambambili 100110 luba ngu-38: 0 * 2 ^ 01 + 1 * 2 ^ 1 + 1 * 2 ^ 2 + 0 * 2 ^ 3 + 0 * 2 ^ 4 + 1 * 2 ^ 5 = 0 + 2 idesimali + 4 + 0 + 0 + 32. Umbhalo wekhodi we-Base64 uthatha le yunithi yezinhlamvu kanambambili futhi iyihlukanise ibe amanani angu-6-bit 38, 58, 11 kanye no-41. Ekugcineni, lezi zinombolo ziguqulelwa kuzinhlamvu ze-ASCII kusetshenziswa ithebula lombhalo wekhodi ye-Base64.