<bdo id='7UIka'></bdo><ul id='7UIka'></ul>
  • <i id='7UIka'><tr id='7UIka'><dt id='7UIka'><q id='7UIka'><span id='7UIka'><b id='7UIka'><form id='7UIka'><ins id='7UIka'></ins><ul id='7UIka'></ul><sub id='7UIka'></sub></form><legend id='7UIka'></legend><bdo id='7UIka'><pre id='7UIka'><center id='7UIka'></center></pre></bdo></b><th id='7UIka'></th></span></q></dt></tr></i><div id='7UIka'><tfoot id='7UIka'></tfoot><dl id='7UIka'><fieldset id='7UIka'></fieldset></dl></div>

      <small id='7UIka'></small><noframes id='7UIka'>

        <tfoot id='7UIka'></tfoot>

        <legend id='7UIka'><style id='7UIka'><dir id='7UIka'><q id='7UIka'></q></dir></style></legend>

      1. 如何在 Java 中将整数添加到 char 中?

        时间:2023-07-27

          <legend id='cS3CK'><style id='cS3CK'><dir id='cS3CK'><q id='cS3CK'></q></dir></style></legend>
            <bdo id='cS3CK'></bdo><ul id='cS3CK'></ul>
            <tfoot id='cS3CK'></tfoot>

              <i id='cS3CK'><tr id='cS3CK'><dt id='cS3CK'><q id='cS3CK'><span id='cS3CK'><b id='cS3CK'><form id='cS3CK'><ins id='cS3CK'></ins><ul id='cS3CK'></ul><sub id='cS3CK'></sub></form><legend id='cS3CK'></legend><bdo id='cS3CK'><pre id='cS3CK'><center id='cS3CK'></center></pre></bdo></b><th id='cS3CK'></th></span></q></dt></tr></i><div id='cS3CK'><tfoot id='cS3CK'></tfoot><dl id='cS3CK'><fieldset id='cS3CK'></fieldset></dl></div>
                  <tbody id='cS3CK'></tbody>

                  <small id='cS3CK'></small><noframes id='cS3CK'>

                  本文介绍了如何在 Java 中将整数添加到 char 中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在用 Java 编写密码,但我无法执行以下操作:我想编辑一个 char 数组的值来加密它

                  I'm making a Cipher in Java but I can't do the follwing thing: I want to edit the value of a char array to encrypt it

                  我应该怎么做?

                  更改每个字符的 ASCII 值可能是答案,我不知道;这就是我问你们的原因!

                  Changing the ASCII value of each char might be the answer, I don't know; that's why I'm asking you Guys!

                  推荐答案

                  你可以在 char 中添加一个 int,但结果是一个 int - 你必须转换回 char 才能把它放回数组中,除非你使用复合赋值运算符:

                  You can add an int to a char, but the result is an int - you'd have to cast back to char to put it back in the array, unless you use the compound assignment operator:

                  array[x] += someInt;
                  

                  array[x] = (char) (array[x] + someInt);
                  

                  但是,通常这不是执行加密的适当方式.您通常会得到不可打印的字符,或者在 Unicode 中甚至没有特定含义的字符.相反,大多数加密算法旨在处理任意二进制数据——即字节数组.

                  However, usually this isn't an appropriate way of performing encryption. You'll often end up with unprintable characters, or characters which don't even have a specific meaning in Unicode. Instead, most encryption algorithms are designed to work on arbitrary binary data - i.e. byte arrays.

                  通常您会先将字符串转换为字节数组(例如,使用 String.getBytes(charset) - 一定要指定编码).然后对字节数组进行加密,给你一个新的字节数组.如果您真的需要将其转换回文本,请使用 base64 执行此操作 - 使用 new String(encryptedBytes),因为您没有不再有以普通文本编码方式编码的文本数据.

                  Usually you would convert the string into a byte array first (e.g. with String.getBytes(charset) - definitely specify an encoding). Then perform encryption on the byte array, giving you a new byte array. If you really need to convert it back to text, use base64 to do so - do not use new String(encryptedBytes), as you no longer have text data encoded in a normal text encoding.

                  这篇关于如何在 Java 中将整数添加到 char 中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:从代码点编号的 IntStream 中创建一个字符串? 下一篇:Java:如何检查字符是否属于特定的 unicode 块?

                  相关文章

                  最新文章

                    • <bdo id='AJujk'></bdo><ul id='AJujk'></ul>

                    <small id='AJujk'></small><noframes id='AJujk'>

                    <tfoot id='AJujk'></tfoot>
                  1. <i id='AJujk'><tr id='AJujk'><dt id='AJujk'><q id='AJujk'><span id='AJujk'><b id='AJujk'><form id='AJujk'><ins id='AJujk'></ins><ul id='AJujk'></ul><sub id='AJujk'></sub></form><legend id='AJujk'></legend><bdo id='AJujk'><pre id='AJujk'><center id='AJujk'></center></pre></bdo></b><th id='AJujk'></th></span></q></dt></tr></i><div id='AJujk'><tfoot id='AJujk'></tfoot><dl id='AJujk'><fieldset id='AJujk'></fieldset></dl></div>

                    <legend id='AJujk'><style id='AJujk'><dir id='AJujk'><q id='AJujk'></q></dir></style></legend>