GIF89a=( õ' 7IAXKgNgYvYx\%wh…hŽth%ˆs%—x¨}9®Œ©€&©‰%¶†(¹–.¹5·œD¹&Çš)ÇŸ5ǘ;Í£*È¡&Õ²)ׯ7×µ<Ñ»4ï°3ø‘HÖ§KͯT÷¨Yÿšqÿ»qÿÔFØ !ù ' !ÿ NETSCAPE2.0 , =( þÀ“pH,È¤rÉl:ŸÐ¨tJ­Z¯Ø¬vËíz¿à°xL.›Ïè´zÍn»ßð¸|N¯Ûïø¼~Ïïûÿ€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜™š›œžŸ ¡¢£¤¥¦§gª«ªE¯°¨¬ª±²Œ¹º¹E¾­”´ÂB¶¯ §Åȸ»ÑD¾¿Á•ÄÅ®° ÝH¾ÒLÀÆDÙ«D¶BÝïðÀ¾DÑÑÔTÌÍíH òGö¨A RÎڐ |¥ ٭&ºìE8œ¹kGÔAÞpx­a¶­ã R2XB®åE8I€Õ6Xî:vT)äžþÀq¦è³¥ì仕F~%xñ  4#ZÔ‰O|-4Bs‘X:= QÉ œš lºÒyXJŠGȦ|s hÏíK–3l7·B|¥$'7Jީܪ‰‡àá”Dæn=Pƒ ¤Òëí‰`䌨ljóá¯Éüv>á–Á¼5 ½.69ûϸd«­ºÀûnlv©‹ªîf{¬ÜãPbŸ  l5‘ޝpß ´ ˜3aÅùäI«O’ý·‘áÞ‡˜¾Æ‚ÙÏiÇÿ‹Àƒ #öó)pâš Þ½ ‘Ý{ó)vmÞü%D~ 6f s}ŃƒDØW Eþ`‡þ À…L8xá†ç˜{)x`X/> Ì}mø‚–RØ‘*|`D=‚Ø_ ^ð5 !_…'aä“OÚ—7âcð`D”Cx`ÝÂ¥ä‹éY¹—F¼¤¥Š?¡Õ™ n@`} lď’ÄÉ@4>ñd œ à‘vÒxNÃ×™@žd=ˆgsžG±æ ´²æud &p8Qñ)ˆ«lXD©øÜéAžHìySun jª×k*D¤LH] †¦§C™Jä–´Xb~ʪwStŽ6K,°£qÁœ:9ت:¨þªl¨@¡`‚ûÚ ».Û¬¯t‹ÆSÉ[:°=Š‹„‘Nåû”Ìî{¿ÂA ‡Rà›ÀÙ6úë°Ÿð0Ä_ ½;ÃϱîÉì^ÇÛÇ#Ëë¼ôº!±Ä˜íUîÅÇ;0L1óÁµö«p% AÀºU̬ݵ¼á%霼€‡¯Á~`ÏG¯»À× ­²± =4ªnpð3¾¤³¯­ü¾¦îuÙuµÙ®|%2ÊIÿür¦#0·ÔJ``8È@S@5ê¢ ö×Þ^`8EÜ]ý.뜃Âç 7 ú ȉÞj œ½Dç zý¸iþœÑÙûÄë!ˆÞÀl§Ïw‹*DçI€nEX¯¬¼ &A¬Go¼QföõFç°¯;é¦÷îŽêJ°îúôF5¡ÌQ|îúöXªæ»TÁÏyñêï]ê² o óÎC=öõ›ÒÓPB@ D×½œä(>èCÂxŽ`±«Ÿ–JЀ»Û á¤±p+eE0`ëŽ`A Ú/NE€Ø†À9‚@¤à H½7”à‡%B‰`Àl*ƒó‘–‡8 2ñ%¸ —€:Ù1Á‰E¸àux%nP1ð!‘ðC)¾P81lÑɸF#ˆ€{´âé°ÈB„0>±û °b¡Š´±O‚3È–Ù()yRpbµ¨E.Z‘D8ÊH@% òŒx+%Ù˜Æcü »¸˜fõ¬b·d`Fê™8èXH"ÉÈ-±|1Ô6iI, 2““¬$+](A*jÐ QTÂo‰.ÛU슬Œã„Ž`¯SN¡–¶Äåyše¯ª’­¬‚´b¦Éož œ)åyâ@Ì®3 ÎtT̉°&Ø+žLÀf"Ø-|žçÔ>‡Ðv¦Ðžì\‚ Q1)Ž@Žh#aP72”ˆ™¨$‚ !ù " , =( …7IAXG]KgNgYvYxR"k\%w]'}hŽth%ˆg+ˆs%—r.—m3šx3˜x¨}9®€&©€+¨‡7§‰%¶†(¹–.¹œD¹&ǘ;Í•&ײ)×»4ïÌ6ò§KÍ þ@‘pH,È¤rÉl:ŸÐ¨tJ­Z¯Ø¬vËíz¿à°xL.›Ïè´zÍn»ßð¸|N¯Ûïø¼~Ïïûÿ€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜™š›œžŸ ¡¢£¤¥¦§g «¬ E ±± ¨­¶°ººE Á´”·®C¬²§Ç¶Œ»ÓDÃÕƷ¯Ê±H½ºM×ÁGÚ¬D¶BËÁ½î½DÓôTÏÛßîG»ôõC×CÌ l&âž:'òtU³6ɹ#·Ø)€'Ü.6±&ëÍÈ» K(8p0N?!æ2"ÛˆNIJX>R¼ÐO‚M '¡¨2¸*Ÿþ>#n↠å@‚<[:¡Iïf’ ¤TÚ˘CdbÜÙ“[«ŽEú5MBo¤×@€`@„€Êt W-3 ¶Ÿ¡BíêäjIÝ…Eò9[T…$íêﯧ„…•s»Óȳ¹€ÅÚdc®UUρ#±Ùïldj?´í¼²`\ŽÁðÞu|3'ÖŒ]ë6 ¶S#²‡˜FKLÈ *N E´‘áäŠ$˜›eÄYD„ºq«.è촁ƒs \-ÔjA 9²õ÷å- üúM[Âx(ís÷ì®x€|í¡Ù’p¦‚ ŽkÛTÇDpE@WÜ ²Ç]kŠ1¨ þ€·Yb ÓÁ‰l°*n0 ç™—žzBdОu¾7ĉBl€â‰-ºx~|UåU‰  h*Hœ|e"#"?vpÄiŠe6^ˆ„+qâŠm8 #VÇá ‘å–ÄV„œ|Аè•m"сœn|@›U¶ÆÎž—Špb¥G¨ED”€±Úê2FÌIç? >Éxå Œ± ¡¤„%‘žjŸ‘ꄯ<Ìaà9ijÐ2˜D¦È&›†Z`‚å]wþ¼Â:ç6àB¤7eFJ|õÒ§Õ,¨äàFÇ®cS·Ê¶+B°,‘Þ˜ºNûãØ>PADÌHD¹æž«ÄÀnÌ¥}­#Ë’ë QÀÉSÌÂÇ2ÌXÀ{æk²lQÁ2«ÊðÀ¯w|2Í h‹ÄÂG€,m¾¶ë3ÐÙ6-´ÅE¬L°ÆIij*K½ÀÇqï`DwVÍQXœÚÔpeœ±¬Ñ q˜§Tœ½µƒ°Œìu Â<¶aØ*At¯lmEØ ü ôÛN[P1ÔÛ¦­±$ÜÆ@`ùåDpy¶yXvCAyåB`ŽD¶ 0QwG#¯ æš[^Äþ $ÀÓÝǦ{„L™[±úKÄgÌ;ï£S~¹ìGX.ôgoT.»åˆ°ùŸûù¡?1zö¦Ÿž:ÅgÁ|ìL¹ „®£œŠ‚à0œ]PÁ^p F<"•ç?!,ñ‡N4—…PÄ Á„ö¨Û:Tè@hÀ‹%táÿ:ø-žI<`þ‹p I….)^ 40D#p@ƒj4–؀:²‰1Øâr˜¼F2oW¼#Z†;$Q q” ‘ ÂK¦ñNl#29 !’F@¥Bh·ᏀL!—XFóLH‘Kh¤.«hE&JòG¨¥<™WN!€ÑÙÚˆY„@†>Œž19J" 2,/ &.GXB%ÌRÈ9B6¹W]’î×ÔW¥’IÎ$ ñ‹ÓŒE8YÆ ¼³™ñA5“à®Q.aŸB€&Ø©³ JÁ—! ¦t)K%tœ-¦JF bòNMxLôþ)ÐR¸Ð™‘ èÝ6‘O!THÌ„HÛ ‰ !ù ) , =( …AXKgNgYvYxR"k\%wh…hŽh%ˆg+ˆs%—r.—x3˜x¨}9®€&©€+¨Œ,©‡7§‰%¶†(¹–.¹5·&Çš)ǘ;Í•&×£*Ȳ)ׯ7×»4ï°3øÌ6ò‘HÖ§KÍ»Hó¯T÷¨Yÿ»qÿÇhÿ þÀ”pH,È¤rÉl:ŸÐ¨tJ­Z¯Ø¬vËíz¿à°xL.›Ïè´zÍn»ßð¸|N¯Ûïø¼~Ïïûÿ€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜™š›œžŸ ¡¢£¤¥¦§g ª« E$±²¨ª­ · °²½$E$ÂÕ««D· Í ¿¦Ç¶¸ÌŒ¾³CÃÅÆ E ééH½MÛÂGâªD­ çBêêϾD²ÒaÀà€Š1r­ðÓ¤ ÔožzU!L˜C'¾yW½UGtäÇïÙllê0×àÂuGþ)AÀs[þ·xì ÁxO%ƒûX2ó—  P£n›R/¡ÑšHše+êDm?# —‘Ç£6¡8íJ¡ŸâDiäªM¥Ö„ôj“¬¹£5oQ7°- <‡ *´lãÓŒ2r/a!l)dÈ A™ÈE¢ôÔ͆…ð ;Ö˜c ¡%ß‚’Ùˆâ¸b½—pe~C"BíëÚHïeF2§æŠ8qb t_`urŠeü wÅu3êæPv§h•"ß`íÍxçLĹÜÖ3á  ~Öº“®›¸ÏMDfJÙ °„ÛµáWõ%§œ‚à©–‚X ÓØ)@®Ñ›Eþ´wëuÅSxb8y\mÖzœ¥§ZbºE—ÂLªÌw!y(>¡™wú=Ç|ÅÝs¢d €CÁW)HÜcC$€L Ä7„r.á\{)@ð` @ äXÈ$PD” `šaG:§æˆOˆ72EÐamn]ù"ŒcÊxÑŒ° &dR8`g«iÙŸLR!¦P …d’ä¡“¦ðÎTƒ¦ià|À _ ¥ Qi#¦Šg›Æ ›noMµ ›V ã£)p ç£ÎW…š=Âeªk§†j„ ´®1ß²sÉxéW«jšl|0¯B0Û, \jÛ´›6±¬¶C ÛíWþï|ëÙ‹¸ñzĸV {ì;Ýñn¼òVˆm³I¼³.Ðã¤PN¥ ²µ¼„µCã+¹ÍByî£Ñ¾HŸ›ëê 7ìYÆFTk¨SaoaY$Dµœìï¿Ã29RÈkt Çïfñ ÇÒ:ÀÐSp¹3ÇI¨â¥DZÄ ü9Ïýögñ½­uÔ*3)O‘˜Ö[_hv ,àî×Et Ÿé¶BH€ Õ[ü±64M@ÔSÌM7dÐl5-ÄÙU܍´©zߌ3Ô€3ž„ „ ¶ÛPô½5×g› êÚ˜kN„Ý…0Îj4€Ìë°“#{þÕ3S2çKÜ'ợlø¼Ú2K{° {Û¶?žm𸧠ËI¼nEò='êüóºè^üæÃ_Û=°óž‚ì#Oý¿Í'¡½áo..ÏYìnüñCœO±Áa¿¢Kô½o,üÄËbö²çºíï{ËC Ú— "”Ï{ËK ÍÒw„õ±Oz dÕ¨à:$ ƒô—«v»] A#ð «€¿šéz)Rx׿ˆ¥‚d``èw-îyÏf×K!ð€þ­Ð|ìPľ„=Ì`ý(f” 'Pa ¥ÐBJa%Ðâf§„%Š¡}FàáÝ×6>ÉäŠG"éŽè=ø!oа^FP¼Ø©Q„ÀCÙÁ`(Ž\ÄÝ® ©Â$<n@dÄ E#ììUÒI! ‚#lù‹`k¦ÐÇ'Rró’ZýNBÈMF Í[¤+‹ðɈ-áwj¨¥þ8¾rá ,VÂh„"|½œ=×G_¦Ñ™EØ 0i*%̲˜Æda0mV‚k¾)›;„&6 p>ÓjK “¦Ç# âDÂ:ûc?:R Ó¬fÞéI-Ì“•Ã<ä=™Ï7˜3œ¨˜c2ŒW ,ˆ”8(T™P‰F¡Jhç"‚ ; 403WebShell
403Webshell
Server IP : 104.21.83.152  /  Your IP : 216.73.216.195
Web Server : LiteSpeed
System : Linux premium229.web-hosting.com 4.18.0-553.45.1.lve.el8.x86_64 #1 SMP Wed Mar 26 12:08:09 UTC 2025 x86_64
User : akhalid ( 749)
PHP Version : 8.3.22
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /opt/alt/ruby33/share/ruby/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /opt/alt/ruby33/share/ruby//base64.rb
# frozen_string_literal: true
#
# \Module \Base64 provides methods for:
#
# - Encoding a binary string (containing non-ASCII characters)
#   as a string of printable ASCII characters.
# - Decoding such an encoded string.
#
# \Base64 is commonly used in contexts where binary data
# is not allowed or supported:
#
# - Images in HTML or CSS files, or in URLs.
# - Email attachments.
#
# A \Base64-encoded string is about one-third larger that its source.
# See the {Wikipedia article}[https://en.wikipedia.org/wiki/Base64]
# for more information.
#
# This module provides three pairs of encode/decode methods.
# Your choices among these methods should depend on:
#
# - Which character set is to be used for encoding and decoding.
# - Whether "padding" is to be used.
# - Whether encoded strings are to contain newlines.
#
# Note: Examples on this page assume that the including program has executed:
#
#   require 'base64'
#
# == Encoding Character Sets
#
# A \Base64-encoded string consists only of characters from a 64-character set:
#
# - <tt>('A'..'Z')</tt>.
# - <tt>('a'..'z')</tt>.
# - <tt>('0'..'9')</tt>.
# - <tt>=</tt>, the 'padding' character.
# - Either:
#   - <tt>%w[+ /]</tt>:
#     {RFC-2045-compliant}[https://datatracker.ietf.org/doc/html/rfc2045];
#     _not_ safe for URLs.
#   - <tt>%w[- _]</tt>:
#     {RFC-4648-compliant}[https://datatracker.ietf.org/doc/html/rfc4648];
#     safe for URLs.
#
# If you are working with \Base64-encoded strings that will come from
# or be put into URLs, you should choose this encoder-decoder pair
# of RFC-4648-compliant methods:
#
# - Base64.urlsafe_encode64 and Base64.urlsafe_decode64.
#
# Otherwise, you may choose any of the pairs in this module,
# including the pair above, or the RFC-2045-compliant pairs:
#
# - Base64.encode64 and Base64.decode64.
# - Base64.strict_encode64 and Base64.strict_decode64.
#
# == Padding
#
# \Base64-encoding changes a triplet of input bytes
# into a quartet of output characters.
#
# <b>Padding in Encode Methods</b>
#
# Padding -- extending an encoded string with zero, one, or two trailing
# <tt>=</tt> characters -- is performed by methods Base64.encode64,
# Base64.strict_encode64, and, by default, Base64.urlsafe_encode64:
#
#   Base64.encode64('s')                         # => "cw==\n"
#   Base64.strict_encode64('s')                  # => "cw=="
#   Base64.urlsafe_encode64('s')                 # => "cw=="
#   Base64.urlsafe_encode64('s', padding: false) # => "cw"
#
# When padding is performed, the encoded string is always of length <em>4n</em>,
# where +n+ is a non-negative integer:
#
# - Input bytes of length <em>3n</em> generate unpadded output characters
#   of length <em>4n</em>:
#
#     # n = 1:  3 bytes => 4 characters.
#     Base64.strict_encode64('123')      # => "MDEy"
#     # n = 2:  6 bytes => 8 characters.
#     Base64.strict_encode64('123456')   # => "MDEyMzQ1"
#
# - Input bytes of length <em>3n+1</em> generate padded output characters
#   of length <em>4(n+1)</em>, with two padding characters at the end:
#
#     # n = 1:  4 bytes => 8 characters.
#     Base64.strict_encode64('1234')     # => "MDEyMw=="
#     # n = 2:  7 bytes => 12 characters.
#     Base64.strict_encode64('1234567')  # => "MDEyMzQ1Ng=="
#
# - Input bytes of length <em>3n+2</em> generate padded output characters
#   of length <em>4(n+1)</em>, with one padding character at the end:
#
#     # n = 1:  5 bytes => 8 characters.
#     Base64.strict_encode64('12345')    # => "MDEyMzQ="
#     # n = 2:  8 bytes => 12 characters.
#     Base64.strict_encode64('12345678') # => "MDEyMzQ1Njc="
#
# When padding is suppressed, for a positive integer <em>n</em>:
#
# - Input bytes of length <em>3n</em> generate unpadded output characters
#   of length <em>4n</em>:
#
#     # n = 1:  3 bytes => 4 characters.
#     Base64.urlsafe_encode64('123', padding: false)      # => "MDEy"
#     # n = 2:  6 bytes => 8 characters.
#     Base64.urlsafe_encode64('123456', padding: false)   # => "MDEyMzQ1"
#
# - Input bytes of length <em>3n+1</em> generate unpadded output characters
#   of length <em>4n+2</em>, with two padding characters at the end:
#
#     # n = 1:  4 bytes => 6 characters.
#     Base64.urlsafe_encode64('1234', padding: false)     # => "MDEyMw"
#     # n = 2:  7 bytes => 10 characters.
#     Base64.urlsafe_encode64('1234567', padding: false)  # => "MDEyMzQ1Ng"
#
# - Input bytes of length <em>3n+2</em> generate unpadded output characters
#   of length <em>4n+3</em>, with one padding character at the end:
#
#     # n = 1:  5 bytes => 7 characters.
#     Base64.urlsafe_encode64('12345', padding: false)    # => "MDEyMzQ"
#     # m = 2:  8 bytes => 11 characters.
#     Base64.urlsafe_encode64('12345678', padding: false) # => "MDEyMzQ1Njc"
#
# <b>Padding in Decode Methods</b>
#
# All of the \Base64 decode methods support (but do not require) padding.
#
# \Method Base64.decode64 does not check the size of the padding:
#
#   Base64.decode64("MDEyMzQ1Njc") # => "01234567"
#   Base64.decode64("MDEyMzQ1Njc=") # => "01234567"
#   Base64.decode64("MDEyMzQ1Njc==") # => "01234567"
#
# \Method Base64.strict_decode64 strictly enforces padding size:
#
#   Base64.strict_decode64("MDEyMzQ1Njc")   # Raises ArgumentError
#   Base64.strict_decode64("MDEyMzQ1Njc=")  # => "01234567"
#   Base64.strict_decode64("MDEyMzQ1Njc==") # Raises ArgumentError
#
# \Method Base64.urlsafe_decode64 allows padding in +str+,
# which if present, must be correct:
# see {Padding}[Base64.html#module-Base64-label-Padding], above:
#
#   Base64.urlsafe_decode64("MDEyMzQ1Njc") # => "01234567"
#   Base64.urlsafe_decode64("MDEyMzQ1Njc=") # => "01234567"
#   Base64.urlsafe_decode64("MDEyMzQ1Njc==") # Raises ArgumentError.
#
# == Newlines
#
# An encoded string returned by Base64.encode64 or Base64.urlsafe_encode64
# has an embedded newline character
# after each 60-character sequence, and, if non-empty, at the end:
#
#   # No newline if empty.
#   encoded = Base64.encode64("\x00" *  0)
#   encoded.index("\n") # => nil
#
#   # Newline at end of short output.
#   encoded = Base64.encode64("\x00" *  1)
#   encoded.size        # => 4
#   encoded.index("\n") # => 4
#
#   # Newline at end of longer output.
#   encoded = Base64.encode64("\x00" * 45)
#   encoded.size        # => 60
#   encoded.index("\n") # => 60
#
#   # Newlines embedded and at end of still longer output.
#   encoded = Base64.encode64("\x00" * 46)
#   encoded.size                          # => 65
#   encoded.rindex("\n")                  # => 65
#   encoded.split("\n").map {|s| s.size } # => [60, 4]
#
# The string to be encoded may itself contain newlines,
# which are encoded as \Base64:
#
#      #   Base64.encode64("\n\n\n") # => "CgoK\n"
#    s = "This is line 1\nThis is line 2\n"
#    Base64.encode64(s) # => "VGhpcyBpcyBsaW5lIDEKVGhpcyBpcyBsaW5lIDIK\n"
#
module Base64

  VERSION = "0.2.0"

  module_function

  # Returns a string containing the RFC-2045-compliant \Base64-encoding of +bin+.
  #
  # Per RFC 2045, the returned string may contain the URL-unsafe characters
  # <tt>+</tt> or <tt>/</tt>;
  # see {Encoding Character Set}[Base64.html#module-Base64-label-Encoding+Character+Sets] above:
  #
  #   Base64.encode64("\xFB\xEF\xBE") # => "++++\n"
  #   Base64.encode64("\xFF\xFF\xFF") # => "////\n"
  #
  # The returned string may include padding;
  # see {Padding}[Base64.html#module-Base64-label-Padding] above.
  #
  #   Base64.encode64('*') # => "Kg==\n"
  #
  # The returned string ends with a newline character, and if sufficiently long
  # will have one or more embedded newline characters;
  # see {Newlines}[Base64.html#module-Base64-label-Newlines] above:
  #
  #   Base64.encode64('*') # => "Kg==\n"
  #   Base64.encode64('*' * 46)
  #   # => "KioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioq\nKg==\n"
  #
  # The string to be encoded may itself contain newlines,
  # which will be encoded as ordinary \Base64:
  #
  #   Base64.encode64("\n\n\n") # => "CgoK\n"
  #   s = "This is line 1\nThis is line 2\n"
  #   Base64.encode64(s) # => "VGhpcyBpcyBsaW5lIDEKVGhpcyBpcyBsaW5lIDIK\n"
  #
  def encode64(bin)
    [bin].pack("m")
  end

  # Returns a string containing the decoding of an RFC-2045-compliant
  # \Base64-encoded string +str+:
  #
  #   s = "VGhpcyBpcyBsaW5lIDEKVGhpcyBpcyBsaW5lIDIK\n"
  #   Base64.decode64(s) # => "This is line 1\nThis is line 2\n"
  #
  # Non-\Base64 characters in +str+ are ignored;
  # see {Encoding Character Set}[Base64.html#module-Base64-label-Encoding+Character+Sets] above:
  # these include newline characters and characters <tt>-</tt> and <tt>/</tt>:
  #
  #   Base64.decode64("\x00\n-_") # => ""
  #
  # Padding in +str+ (even if incorrect) is ignored:
  #
  #   Base64.decode64("MDEyMzQ1Njc")   # => "01234567"
  #   Base64.decode64("MDEyMzQ1Njc=")  # => "01234567"
  #   Base64.decode64("MDEyMzQ1Njc==") # => "01234567"
  #
  def decode64(str)
    str.unpack1("m")
  end

  # Returns a string containing the RFC-2045-compliant \Base64-encoding of +bin+.
  #
  # Per RFC 2045, the returned string may contain the URL-unsafe characters
  # <tt>+</tt> or <tt>/</tt>;
  # see {Encoding Character Set}[Base64.html#module-Base64-label-Encoding+Character+Sets] above:
  #
  #   Base64.strict_encode64("\xFB\xEF\xBE") # => "++++\n"
  #   Base64.strict_encode64("\xFF\xFF\xFF") # => "////\n"
  #
  # The returned string may include padding;
  # see {Padding}[Base64.html#module-Base64-label-Padding] above.
  #
  #   Base64.strict_encode64('*') # => "Kg==\n"
  #
  # The returned string will have no newline characters, regardless of its length;
  # see {Newlines}[Base64.html#module-Base64-label-Newlines] above:
  #
  #   Base64.strict_encode64('*') # => "Kg=="
  #   Base64.strict_encode64('*' * 46)
  #   # => "KioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKg=="
  #
  # The string to be encoded may itself contain newlines,
  # which will be encoded as ordinary \Base64:
  #
  #   Base64.strict_encode64("\n\n\n") # => "CgoK"
  #   s = "This is line 1\nThis is line 2\n"
  #   Base64.strict_encode64(s) # => "VGhpcyBpcyBsaW5lIDEKVGhpcyBpcyBsaW5lIDIK"
  #
  def strict_encode64(bin)
    [bin].pack("m0")
  end

  # Returns a string containing the decoding of an RFC-2045-compliant
  # \Base64-encoded string +str+:
  #
  #   s = "VGhpcyBpcyBsaW5lIDEKVGhpcyBpcyBsaW5lIDIK"
  #   Base64.strict_decode64(s) # => "This is line 1\nThis is line 2\n"
  #
  # Non-\Base64 characters in +str+ not allowed;
  # see {Encoding Character Set}[Base64.html#module-Base64-label-Encoding+Character+Sets] above:
  # these include newline characters and characters <tt>-</tt> and <tt>/</tt>:
  #
  #   Base64.strict_decode64("\n") # Raises ArgumentError
  #   Base64.strict_decode64('-')  # Raises ArgumentError
  #   Base64.strict_decode64('_')  # Raises ArgumentError
  #
  # Padding in +str+, if present, must be correct:
  #
  #   Base64.strict_decode64("MDEyMzQ1Njc")   # Raises ArgumentError
  #   Base64.strict_decode64("MDEyMzQ1Njc=")  # => "01234567"
  #   Base64.strict_decode64("MDEyMzQ1Njc==") # Raises ArgumentError
  #
  def strict_decode64(str)
    str.unpack1("m0")
  end

  # Returns the RFC-4648-compliant \Base64-encoding of +bin+.
  #
  # Per RFC 4648, the returned string will not contain the URL-unsafe characters
  # <tt>+</tt> or <tt>/</tt>,
  # but instead may contain the URL-safe characters
  # <tt>-</tt> and <tt>_</tt>;
  # see {Encoding Character Set}[Base64.html#module-Base64-label-Encoding+Character+Sets] above:
  #
  #   Base64.urlsafe_encode64("\xFB\xEF\xBE") # => "----"
  #   Base64.urlsafe_encode64("\xFF\xFF\xFF") # => "____"
  #
  # By default, the returned string may have padding;
  # see {Padding}[Base64.html#module-Base64-label-Padding], above:
  #
  #   Base64.urlsafe_encode64('*') # => "Kg=="
  #
  # Optionally, you can suppress padding:
  #
  #   Base64.urlsafe_encode64('*', padding: false) # => "Kg"
  #
  # The returned string will have no newline characters, regardless of its length;
  # see {Newlines}[Base64.html#module-Base64-label-Newlines] above:
  #
  #   Base64.urlsafe_encode64('*') # => "Kg=="
  #   Base64.urlsafe_encode64('*' * 46)
  #   # => "KioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKg=="
  #
  def urlsafe_encode64(bin, padding: true)
    str = strict_encode64(bin)
    str.chomp!("==") or str.chomp!("=") unless padding
    str.tr!("+/", "-_")
    str
  end

  # Returns the decoding of an RFC-4648-compliant \Base64-encoded string +str+:
  #
  # +str+ may not contain non-Base64 characters;
  # see {Encoding Character Set}[Base64.html#module-Base64-label-Encoding+Character+Sets] above:
  #
  #   Base64.urlsafe_decode64('+')  # Raises ArgumentError.
  #   Base64.urlsafe_decode64('/')  # Raises ArgumentError.
  #   Base64.urlsafe_decode64("\n") # Raises ArgumentError.
  #
  # Padding in +str+, if present, must be correct:
  # see {Padding}[Base64.html#module-Base64-label-Padding], above:
  #
  #   Base64.urlsafe_decode64("MDEyMzQ1Njc") # => "01234567"
  #   Base64.urlsafe_decode64("MDEyMzQ1Njc=") # => "01234567"
  #   Base64.urlsafe_decode64("MDEyMzQ1Njc==") # Raises ArgumentError.
  #
  def urlsafe_decode64(str)
    # NOTE: RFC 4648 does say nothing about unpadded input, but says that
    # "the excess pad characters MAY also be ignored", so it is inferred that
    # unpadded input is also acceptable.
    if !str.end_with?("=") && str.length % 4 != 0
      str = str.ljust((str.length + 3) & ~3, "=")
      str.tr!("-_", "+/")
    else
      str = str.tr("-_", "+/")
    end
    strict_decode64(str)
  end
end

Youez - 2016 - github.com/yon3zu
LinuXploit