Problem Description
Mike does not want others to view his messages, so he find a encode method Base64.

Here is an example of the note in Chinese Passport.

The Ministry of Foreign Affairs of the People's Republic of China requests all civil and military authorities of foreign countries to allow the bearer of this passport to pass freely and afford assistance in case of need.

When encoded by \texttt{Base64}, it looks as follows

VGhlIE1pbmlzdHJ5IG9mIEZvcmVpZ24gQWZmYWlycyBvZiB0aGUgUGVvcGxlJ3MgUmVwdWJsaWMgb2Yg
Q2hpbmEgcmVxdWVzdHMgYWxsIGNpdmlsIGFuZCBtaWxpdGFyeSBhdXRob3JpdGllcyBvZiBmb3JlaWdu
IGNvdW50cmllcyB0byBhbGxvdyB0aGUgYmVhcmVyIG9mIHRoaXMgcGFzc3BvcnQgdG8gcGFzcyBmcmVl
bHkgYW5kIGFmZm9yZCBhc3Npc3RhbmNlIGluIGNhc2Ugb2YgbmVlZC4=

In the above text, the encoded result of \texttt{The} is \texttt{VGhl}. Encoded in ASCII, the characters \texttt{T}, \texttt{h}, and \texttt{e} are stored as the bytes 84, 104, and 101, which are the 8-bit binary values 01010100, 01101000, and 01100101. These three values are joined together into a 24-bit string, producing 010101000110100001100101.
Groups of 6 bits (6 bits have a maximum of 26=64 different binary values) are converted into individual numbers from left to right (in this case, there are four numbers in a 24-bit string), which are then converted into their corresponding Base64 encoded characters. The Base64 index table is

0123456789012345678901234567890123456789012345678901234567890123
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/

In the above example, the string 010101000110100001100101 is divided into four parts 010101, 000110, 100001 and 100101, and converted into integers 21,6,33 and 37. Then we find them in the table, and get V, G, h, l.

When the number of bytes to encode is not divisible by three (that is, if there are only one or two bytes of input for the last 24-bit block), then the following action is performed:

Add extra bytes with value zero so there are three bytes, and perform the conversion to base64. If there was only one significant input byte, only the first two base64 digits are picked (12 bits), and if there were two significant input bytes, the first three base64 digits are picked (18 bits). '=' characters are added to make the last block contain four base64 characters.

As a result, when the last group contains one bytes, the four least significant bits of the final 6-bit block are set to zero; and when the last group contains two bytes, the two least significant bits of the final 6-bit block are set to zero.

For example, base64(A) = QQ==, base64(AA) = QUE=.

Now, Mike want you to help him encode a string for k times. Can you help him?

For example, when we encode A for two times, we will get base64(base64(A)) = UVE9PQ==.

Input
The first line contains an integer T(T≤20) denoting the number of test cases.

In the following T lines, each line contains a case. In each case, there is a number k(1≤k≤5) and a string s. s only contains characters whose ASCII value are from 33 to 126(all visible characters). The length of s is no larger than 100.

Output
For each test case, output Case #t:, to represent this is t-th case. And then output the encoded string.

Sample Input
2
1 Mike
4 Mike

Sample Output
Case #1: TWlrZQ==
Case #2: Vmtaa2MyTnNjRkpRVkRBOQ==

PHP：Base64解码将字符串转换为其他格式，如十进制或二进制

<div class="post-text" itemprop="text"> <p>I'm trying to use a service which "base64 converts" their data which they then push to my server. The data is divided into three data types: strings, integers and booleans. Why they package it this way I don't understand, but it's up to me to decipher it.</p> <p>I have a string <code>Qjo0MDk2</code> which should convert to <code>B:4096</code> and PHP's native <code>base64_decode</code> function works!</p> <p>However, if I try to convert <code>AAATmg==</code> to a base-10 (decimal) integer value, I want to get <code>5018</code>, but <code>base64_decode</code> just gives me nothing. (I assume because it's trying to convert to a string, rather than a base-10 integer.)</p> <p>Likewise, <code>AA==</code> should convert to <code>0</code> in base-2 (binary) boolean values, while <code>AQ==</code> should convert to <code>1</code> in the same.</p> <p>Is there a set of functions that does this already somewhere? I can't imagine this is new. Here is a website that does it today, but the code is not exposed: <a href="https://conv.darkbyte.ru/" rel="nofollow noreferrer">https://conv.darkbyte.ru/</a></p> </div>

JAVA字符串Base64编码转换

<div class="post-text" itemprop="text"> <p>I have following code which decodes base64 and then encodes it to hex.</p> <pre><code>doc_id := "Can35qPeFkm9Xgmp9+aj3g==" base64_decode, err := base64.StdEncoding.DecodeString(doc_id) if err != nil { log.Fatal("error:", err) } base64_decoded := fmt.Sprintf("%q", base64_decode) fmt.Printf("base_decoded %v ", base64_decoded) src := []byte(base64_decoded) fmt.Println(src) hex_encode := make([]byte, hex.EncodedLen(len(src))) hex.Encode(hex_encode, src) hex_encoded := fmt.Sprintf("%s", hex_encode) fmt.Printf("hex_encoded %v", hex_encoded) </code></pre> <p>where doc_id is base64 format. base64_decoded is its decoded value. I have to encode it to hex, so i pass it to src.</p> <p>The problem is when i pass the identifier base64_decoded to src i get wrong when i pass in the value that base64_decoded is holding i get correct answer. for example: if i get base64_decoded value as "\x11z\xc0[d~\xfcK\xb1\xf8\x11z\xc0[d~" if i pass its value which is "\x11z\xc0[d~\xfcK\xb1\xf8\x11z\xc0[d~", i get correct answer 117ac05b647efc4bb1f8117ac05b647e</p> <p>if i pass the variable holding "\x11z\xc0[d~\xfcK\xb1\xf8\x11z\xc0[d~" i get wrong answer 225c7831317a5c7863305b647e5c7866634b5c7862315c7866385c7831317a5c7863305b647e22dn</p> <p>Has it got something with this assignment <strong>base64_decoded := fmt.Sprintf("%q", base64_decode)</strong></p> <p>what am i doing wrong</p> </div>

base64编码字符串怎么写入到xml文件中

base64编码形成的字符串是否可以压缩

java PDF 转二进制字符串

[code="java"]byte[] b = new byte[fis.available()]; StringBuilder str = new StringBuilder(); fis.read(b); for(byte bs:b){ str.append(Integer.toBinaryString(bs));//转换为二进制 } fis.close();[/code] 我通过这种方式将一个byte[]转换为二进制的字符串。里面全是0和1字符。现怎么将这种二进制字符串转换为byte[]数组？我知道有其它将byte[]和字符串之间互相转换的方法。但我现在只求这种二进制字符串的转换方法。拜托各位了。。

base64，解出来二进制数据，非可见字符。这个怎么解码，AAAjkFyjAyUAHh4AAAAAAAAAAAAAAAAAAAAAAAAAAAA

String str = "AAAjkFyjAyUAHh4AAAAAAAAAAAAAAAAAAAAAAAAAAAA"; byte[] asBytes = Base64.getDecoder().decode(str); System.out.println(asBytes.length); StringBuffer result = new StringBuffer(); for (int i = 0; i < asBytes.length; i++) { result.append(Long.toString(asBytes[i] & 0xff, 2) + ","); System.out.print(StringUtils.leftPad(Integer.toBinaryString(asBytes[i] & 0xff), 8, '0')+","); } ``` ```

js本地图片剪裁后和表单一起提交到服务器，剪裁后图片为base64编码字符串，或者Blob二进制对象

<div class="post-text" itemprop="text"> <p>I want to get size of the original file from a string variable, which is obtained by using a base64 encode file.</p> <pre class="lang-golang prettyprint-override"><code> package main import ( "bufio" "encoding/base64" "io/ioutil" "os" ) func encodeFile(file string) string { f, err := os.Open(file) if err != nil { panic(err) } reader := bufio.NewReader(f) content, _ := ioutil.ReadAll(reader) encoded := base64.StdEncoding.EncodeToString(content) return encoded } func main() { datas := encodeFile("/tmp/hello.json") //how to get file size from datas } </code></pre> <p>how to get the file size from <code>datas</code>? thks.</p> </div>

<div class="post-text" itemprop="text"> <p>In <code>Binary Search Algorithm</code>,</p> <p>in general </p> <pre><code>if mid_value &gt; search_element we set high = mid_pos-1 ; else mid_value &lt; search_element we set low = mid_pos+1 ; </code></pre> <p>But I've just modified the algorithm like these</p> <pre><code>if mid_value &gt; search_element we set high = mid_pos ; else mid_value &lt; search_element we set low = mid_pos ; </code></pre> <p>But my teacher told me that the standard algorithm for <code>binary search</code> is the first one and what you have written is also a search algorithm but it's not an algorithm for binary search. Is he correct?.</p> </div> <p>转载于:https://stackoverflow.com/questions/53058133/a-query-regarding-the-algorithm-of-binary-search-using-c</p>

PHP从base64编码的数据字符串中获取pdf文件

<div class="post-text" itemprop="text"> <p>I have a base64-encoded string containing a pdf. How to create a <code>.pdf</code> file from this encoded string using php? </p> <p>Something like <code>Content-type:application/pdf</code> in header function?</p> <p><a href="http://jenson.in/base64pdf.txt">this is the base64 encoded string</a></p> </div>

A 基于哈夫曼树的数据压缩算法 时间限制(C/C++):1000MS/3000MS 运行内存限制:65536KByte 总提交:445 测试通过:131 描述 输入一串字符串，根据给定的字符串中字符出现的频率建立相应哈夫曼树，构造哈夫曼编码表，在此基础上可以对待压缩文件进行压缩（即编码），同时可以对压缩后的二进制编码文件进行解压（即译码）。 输入 多组数据，每组数据一行，为一个字符串（只考虑26个小写字母即可）。当输入字符串为“0”时，输入结束。 输出 每组数据输出2n+4行（n为输入串中字符类别的个数）。第一行为统计出来的字符出现频率（只输出存在的字符，格式为：字符：频度），每两组字符之间用一个空格分隔，字符按照ASCII码从小到大的顺序排列。第二行至第2n行为哈夫曼树的存储结构的终态（形如教材139页表5.2（b），一行当中的数据用空格分隔）。第2n+2行为每个字符的哈夫曼编码（只输出存在的字符，格式为：字符：编码），每两组字符之间用一个空格分隔，字符按照ASCII码从小到大的顺序排列。第2n+3行为编码后的字符串，第2n+4行为解码后的字符串（与输入的字符串相同）。 样例输入 aaaaaaabbbbbccdddd aabccc 0 样例输出 a:7 b:5 c:2 d:4 1 7 7 0 0 2 5 6 0 0 3 2 5 0 0 4 4 5 0 0 5 6 6 3 4 6 11 7 2 5 7 18 0 1 6 a:0 b:10 c:110 d:111 00000001010101010110110111111111111 aaaaaaabbbbbccdddd a:2 b:1 c:3 1 2 4 0 0 2 1 4 0 0 3 3 5 0 0 4 3 5 2 1 5 6 0 3 4 a:11 b:10 c:0 111110000 aabccc

String s = new String(" a ") 到底产生几个对象？

Linux面试题（2020最新版）

JVM内存结构和Java内存模型别再傻傻分不清了

loonggg读完需要3分钟速读仅需 1 分钟大家好，我是你们的校长。我之前讲过，这年头，只要肯动脑，肯行动，程序员凭借自己的技术，赚钱的方式还是有很多种的。仅仅靠在公司出卖自己的劳动时...

85后蒋凡：28岁实现财务自由、34岁成为阿里万亿电商帝国双掌门，他的人生底层逻辑是什么？...

MySQL数据库面试题（2020最新版）

HashMap底层实现原理，红黑树，B+树，B树的结构原理 Spring的AOP和IOC是什么？它们常见的使用场景有哪些？Spring事务，事务的属性，传播行为，数据库隔离级别 Spring和SpringMVC，MyBatis以及SpringBoot的注解分别有哪些？SpringMVC的工作原理，SpringBoot框架的优点，MyBatis框架的优点 SpringCould组件有哪些，他们...