Base64 Encoding
Hamwe na Base64 Encoding igikoresho, urashobora gushishoza inyandiko winjiye hamwe na Base64. Niba ubishaka, urashobora gushishoza kode ya Base64 hamwe nibikoresho bya Base64.
Encoding ya Base64 ni iki?
Base64 Encoding nigishushanyo mbonera cyemerera amakuru ya binary gutwarwa mubidukikije bikoresha gusa kodegisi yimiterere yabugenewe (ibidukikije aho kode yimiterere yose idashobora gukoreshwa, nka xml, html, inyandiko, ubutumwa bwihuse). Umubare w'inyuguti muri iyi gahunda ni 64, naho umubare 64 mu ijambo Base64 uva hano.
Kuki Ukoresha Base64 Encoding?
Gukenera kodegisi ya Base64 bituruka kubibazo bivuka mugihe itangazamakuru ryoherejwe muburyo bubiri bwibiri kuri sisitemu ishingiye ku nyandiko. Kuberako sisitemu ishingiye kumyandiko (nka e-imeri) isobanura amakuru ya binary nkurwego runini rwinyuguti, harimo inyuguti zidasanzwe, inyinshi mu makuru yoherejwe mu buryo bwo kwimura ibintu zidasobanuwe neza na sisitemu kandi ziratakara cyangwa zangiritse mu kohereza. inzira.
Uburyo bumwe bwo gushiraho amakuru abiri muburyo bwo kwirinda ibibazo nkibi byoherejwe nukubohereza nkumwandiko usanzwe wa ASCII muburyo bwa Base64. Ubu ni bumwe mu buhanga bukoreshwa na MIME yohereza amakuru atari inyandiko isanzwe. Indimi nyinshi zo gutangiza porogaramu, nka PHP na Javascript, zirimo Base64 kodegisi hamwe na decoding imikorere yo gusobanura amakuru yatanzwe hakoreshejwe kodegisi ya Base64.
Base64 Encoding Logic
Muri kodegisi ya Base64, 3 * 8 bits = 24 bits yamakuru agizwe na byite 3 igabanijwe mumatsinda 4 ya 6 bit. Inyuguti zihuye nagaciro keza hagati ya [0-64] yaya matsinda 4 6-biti ahujwe kuva kumeza ya Base64 kugeza kode. Umubare winyuguti zabonetse nkibisubizo bya Base64 bigomba kuba byinshi kuri 4. Encoded data itari myinshi ya 4 ntabwo yemewe Base64. Iyo kodegisi hamwe na algorithm ya Base64, iyo kodegisi irangiye, niba uburebure bwamakuru atari bwinshi bwa 4, inyuguti ya "=" (ingana) yongewe kumpera ya kodegisi kugeza igihe izaba myinshi kuri 4. Kurugero, niba dufite 10-inyuguti ya Base64 yashizwemo amakuru nkibisubizo bya kodegisi, bibiri "==" bigomba kongerwaho kurangiza.
Base64 Encoding Urugero
Kurugero, fata imibare itatu ASCII 155, 162 na 233. Iyi mibare uko ari itatu ikora binary ya 100110111010001011101001. Idosiye ya binary nkishusho ikubiyemo binary ikora kumirongo mirongo cyangwa ibihumbi magana na zeru. Kode ya Base64 itangira igabanya ibice bibiri mumatsinda yinyuguti esheshatu: 100110 111010 001011 101001. Buri tsinda ryasobanuwe mumibare 38, 58, 11, na 41. Imirongo itandatu yinyuguti ihindurwa hagati ya binary (cyangwa shingiro). 2) kuri decimal (base-10) inyuguti muguhuza buri gaciro kagereranijwe na 1 muri binary array hamwe na kare. Guhera iburyo no kwimukira ibumoso ugatangirira kuri zeru, indangagaciro mumigezi ya binary zerekana 2 ^ 0, hanyuma 2 ^ 1, hanyuma 2 ^ 2, hanyuma 2 ^ 3, hanyuma 2 ^ 4, hanyuma 2 ^ 5.
Hano hari ubundi buryo bwo kubireba. Guhera ibumoso, buri mwanya ufite agaciro 1, 2, 4, 8, 16 na 32. Niba ikibanza gifite numero 1, wongeyeho ako gaciro; niba ikibanza gifite 0, urabuze. Binary array 100110 yujuje 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. Kode ya Base64 ifata iyi binary ikayigabanyamo 6-biti 38, 58, 11 na 41. Hanyuma, iyi mibare ihindurwamo inyuguti za ASCII ukoresheje imbonerahamwe ya Base64.