mirror of
https://gitee.com/dromara/hutool.git
synced 2025-04-05 17:37:59 +08:00
1. 增加空判断
2. 优化变量命名
This commit is contained in:
parent
8a4c8eeef3
commit
77c32d8981
@ -17,6 +17,7 @@ public class BCD {
|
||||
* @return BCD
|
||||
*/
|
||||
public static byte[] strToBcd(String asc) {
|
||||
Assert.notNull(asc, "ASCII must not be null!");
|
||||
int len = asc.length();
|
||||
int mod = len % 2;
|
||||
if (mod != 0) {
|
||||
|
@ -1,5 +1,7 @@
|
||||
package cn.hutool.core.codec;
|
||||
|
||||
import cn.hutool.core.lang.Assert;
|
||||
|
||||
/**
|
||||
* 凯撒密码实现<br>
|
||||
* 算法来自:https://github.com/zhaorenjie110/SymmetricEncryptionAndDecryption
|
||||
@ -19,6 +21,7 @@ public class Caesar {
|
||||
* @return 加密后的内容
|
||||
*/
|
||||
public static String encode(String message, int offset) {
|
||||
Assert.notNull(message, "message must be not null!");
|
||||
final int len = message.length();
|
||||
final char[] plain = message.toCharArray();
|
||||
char c;
|
||||
@ -40,6 +43,7 @@ public class Caesar {
|
||||
* @return 解密后的内容
|
||||
*/
|
||||
public static String decode(String cipherText, int offset) {
|
||||
Assert.notNull(cipherText, "cipherText must be not null!");
|
||||
final int len = cipherText.length();
|
||||
final char[] plain = cipherText.toCharArray();
|
||||
char c;
|
||||
|
@ -1,5 +1,6 @@
|
||||
package cn.hutool.core.codec;
|
||||
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.util.CharUtil;
|
||||
import cn.hutool.core.util.HexUtil;
|
||||
@ -51,6 +52,7 @@ public class PercentCodec implements Serializable {
|
||||
* @return PercentCodec
|
||||
*/
|
||||
public static PercentCodec of(CharSequence chars) {
|
||||
Assert.notNull(chars, "chars must not be null");
|
||||
final PercentCodec codec = new PercentCodec();
|
||||
final int length = chars.length();
|
||||
for (int i = 0; i < length; i++) {
|
||||
|
@ -44,6 +44,7 @@ public class PunyCode {
|
||||
* @throws UtilException 计算异常
|
||||
*/
|
||||
public static String encode(CharSequence input, boolean withPrefix) throws UtilException {
|
||||
Assert.notNull(input, "input must not be null!");
|
||||
int n = INITIAL_N;
|
||||
int delta = 0;
|
||||
int bias = INITIAL_BIAS;
|
||||
@ -126,6 +127,7 @@ public class PunyCode {
|
||||
* @throws UtilException 计算异常
|
||||
*/
|
||||
public static String decode(String input) throws UtilException {
|
||||
Assert.notNull(input, "input must not be null!");
|
||||
input = StrUtil.removePrefixIgnoreCase(input, PUNY_CODE_PREFIX);
|
||||
|
||||
int n = INITIAL_N;
|
||||
|
@ -1,5 +1,7 @@
|
||||
package cn.hutool.core.codec;
|
||||
|
||||
import cn.hutool.core.lang.Assert;
|
||||
|
||||
/**
|
||||
* RotN(rotate by N places),回转N位密码,是一种简易的替换式密码,也是过去在古罗马开发的凯撒加密的一种变体。<br>
|
||||
* 代码来自:https://github.com/orclight/jencrypt
|
||||
@ -30,11 +32,11 @@ public class Rot {
|
||||
* Rot-13编码
|
||||
*
|
||||
* @param message 被编码的消息
|
||||
* @param isEnocdeNumber 是否编码数字
|
||||
* @param isEncodeNumber 是否编码数字
|
||||
* @return 编码后的字符串
|
||||
*/
|
||||
public static String encode13(String message, boolean isEnocdeNumber) {
|
||||
return encode(message, 13, isEnocdeNumber);
|
||||
public static String encode13(String message, boolean isEncodeNumber) {
|
||||
return encode(message, 13, isEncodeNumber);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -42,15 +44,16 @@ public class Rot {
|
||||
*
|
||||
* @param message 被编码的消息
|
||||
* @param offset 位移,常用位移13
|
||||
* @param isEnocdeNumber 是否编码数字
|
||||
* @param isEncodeNumber 是否编码数字
|
||||
* @return 编码后的字符串
|
||||
*/
|
||||
public static String encode(String message, int offset, boolean isEnocdeNumber) {
|
||||
public static String encode(String message, int offset, boolean isEncodeNumber) {
|
||||
Assert.notNull(message, "message must not be null");
|
||||
final int len = message.length();
|
||||
final char[] chars = new char[len];
|
||||
|
||||
for (int i = 0; i < len; i++) {
|
||||
chars[i] = encodeChar(message.charAt(i), offset, isEnocdeNumber);
|
||||
chars[i] = encodeChar(message.charAt(i), offset, isEncodeNumber);
|
||||
}
|
||||
return new String(chars);
|
||||
}
|
||||
@ -85,6 +88,7 @@ public class Rot {
|
||||
* @return 解码后的字符串
|
||||
*/
|
||||
public static String decode(String rot, int offset, boolean isDecodeNumber) {
|
||||
Assert.notNull(rot, "rot must not be null");
|
||||
final int len = rot.length();
|
||||
final char[] chars = new char[len];
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user