小编Aye*_*ell的帖子

如何确定字符所需的最小字节数?

有没有办法确定特定编码中字符所需的最小字节数?像mbstring扩展支持的编码之一.UTF-8的值为1,UTF-16的值为2等.

我不想获得特定字符串或字符的长度.

我想知道给定编码支持的最小字符大小,根据它的规范.

我目前使用此代码:

<?php

function flawed_detection($encoding)
{
    // I use 'a' in the hope that this char need the least number of bytes in all the supported encodings
    return strlen(mb_convert_encoding('a', $encoding, 'UTF-8'));
}

foreach (mb_list_encodings() as $encoding) {
    echo "$encoding: ", flawed_detection($encoding), "\n";
}
Run Code Online (Sandbox Code Playgroud)

部分输出:

...
UTF-16LE: 2
UTF-8: 1
UTF-7: 1
UTF7-IMAP: 1
ASCII: 1
EUC-JP: 1
...
Run Code Online (Sandbox Code Playgroud)

但我不确定要使用的"正确"字符.如果有的话.

编辑:我已经在每个编码中测试了从0到U + 10FFFF的每个字符的暴力方法,结果与我的finally_not_so_flawed_detection函数(使用'a'char或空格)完全相同:p

php unicode encoding character-encoding mbstring

5
推荐指数
1
解决办法
112
查看次数

在 Java 卡上安装小程序时出现错误 0x643A

在成功安装(和删除)同一个小程序两次后,我无法再在我的 Java 卡上安装小程序。

设置涉及:

  • 智能卡:ACS ACOSJ 40KB Java Card 3.0.4(双接口)
  • 读卡器:Cherry TC 1300(双接口)
  • CCID 驱动程序:HID Global OMNIKEY ifdokccid_linux_x86_64-v4.2.8
  • 软件:GlobalPlatformPro最新提交

一般卡信息:

$ gp-pro --info --debug --verbose
GlobalPlatformPro v0.3.9-26-gf426164
Running on Linux 4.11.3-1-ARCH amd64, Java 1.8.0_121 by Oracle Corporation
[DEBUG] PlaintextKeys - static keys: 
ENC: Ver:0 ID:0 Type:DES3 Len:16 Value:404142434445464748494A4B4C4D4E4F KCV: 8BAF47
MAC: Ver:0 ID:0 Type:DES3 Len:16 Value:404142434445464748494A4B4C4D4E4F KCV: 8BAF47
KEK: Ver:0 ID:0 Type:DES3 Len:16 Value:404142434445464748494A4B4C4D4E4F KCV: 8BAF47
# Detected readers from JNA2PCSC
[ ] Cherry SC …
Run Code Online (Sandbox Code Playgroud)

applet apdu javacard contactless-smartcard globalplatform

5
推荐指数
0
解决办法
505
查看次数