Embedded Arduino RFID校验和计算和密钥可视化

Embedded Arduino RFID校验和计算和密钥可视化,embedded,arduino,Embedded,Arduino,我将此模块用于Arduino Ethernet R3,我需要从软件序列中检索写在标签外的卡ID。 模块上显示有14个字节被发送到Arduino。第一个是页眉,最后一个是页脚,页脚前的2个字节是校验和,其他10个字节是包含标记ID的ASCII数据 如何重新创建卡的ID并控制校验和?例如,对于ID为0013530444的标记,Arduino响应为: I received: 2 I received: 51 I received: 67 I received: 48 I received: 48 I

我将此模块用于Arduino Ethernet R3,我需要从软件序列中检索写在标签外的卡ID。 模块上显示有14个字节被发送到Arduino。第一个是页眉,最后一个是页脚,页脚前的2个字节是校验和,其他10个字节是包含标记ID的ASCII数据

如何重新创建卡的ID并控制校验和?例如,对于ID为0013530444的标记,Arduino响应为:

I received: 2
I received: 51
I received: 67
I received: 48
I received: 48
I received: 67
I received: 69
I received: 55
I received: 53
I received: 52
I received: 67
I received: 67
I received: 66
I received: 3
但我不知道如何在屏幕上打印Arduino读取的ID。如何计算成本


有人能帮我吗?

这里是如何计算校验和的演练

带上你的卡号这是直接从你的文字中引用的

I received: 2
I received: 51
I received: 67
I received: 48
I received: 48
I received: 67
I received: 69
I received: 55
I received: 53
I received: 52
I received: 67
I received: 67
I received: 66
I received: 3
这将为您提供一个与以下内容等效的数字:

251674848676955535267663

第一个数字2表示这是请求的开始

最后一个数字3表示这是请求的结束

251674848676955535267663

为了计算校验和,我们将删除这两个数字。您的新号码是:

51674867695553526766

您拥有的最后两个数字是您的校验和。剩下的号码是您的卡号。因此:

您的卡号是:

516748676955535267

您的校验和是:

67 66

接下来,您需要将卡号和校验和转换为ASCII值:

您的卡号是:

3C00CE754C

您的校验和是:

C B

接下来,将每个数字配对:

您的卡号是:

3C 00 CE 75 4C

您的校验和是:

CB

然后,您需要将每一对视为十六进制值,并对它们执行异或运算。因此,基本上你需要证明以下几点:

3C^00^CE^75^4C==CB

3C^00=3C

3C^CE^75^4C==CB

3C^CE=F2

F2^75^4C==CB

3C^CE=87

87^4C==CB

87^4C=CB

CB==CB

因为CB==CB,这是一个有效的事务


毫无疑问,其他人可以想出比这更好的方法,但这里应该有足够的伪代码供您自己编写。

下面是如何计算校验和的演练

带上你的卡号这是直接从你的文字中引用的

I received: 2
I received: 51
I received: 67
I received: 48
I received: 48
I received: 67
I received: 69
I received: 55
I received: 53
I received: 52
I received: 67
I received: 67
I received: 66
I received: 3
这将为您提供一个与以下内容等效的数字:

251674848676955535267663

第一个数字2表示这是请求的开始

最后一个数字3表示这是请求的结束

251674848676955535267663

为了计算校验和,我们将删除这两个数字。您的新号码是:

51674867695553526766

您拥有的最后两个数字是您的校验和。剩下的号码是您的卡号。因此:

您的卡号是:

516748676955535267

您的校验和是:

67 66

接下来,您需要将卡号和校验和转换为ASCII值:

您的卡号是:

3C00CE754C

您的校验和是:

C B

接下来,将每个数字配对:

您的卡号是:

3C 00 CE 75 4C

您的校验和是:

CB

然后,您需要将每一对视为十六进制值,并对它们执行异或运算。因此,基本上你需要证明以下几点:

3C^00^CE^75^4C==CB

3C^00=3C

3C^CE^75^4C==CB

3C^CE=F2

F2^75^4C==CB

3C^CE=87

87^4C==CB

87^4C=CB

CB==CB

因为CB==CB,这是一个有效的事务


毫无疑问,其他人可以想出比这更好的方法,但这里应该有足够的伪代码供您自己编写。

我发现它在Arduino中有一个实现,我已经将其改编为在Java中工作,结果很好。因为有很多按位运算,我过去常常试图理解发生了什么。除了我发现的在Arduino中有一个实现的val | tempbyte之外,我了解所有这些内容,我已经将其应用到Java中,结果很好。因为有很多按位运算,我过去常常试图理解发生了什么。除了val | tempbyte之外,我了解所有内容。您可以在这里找到一个ASCII表:供您手动计算。前两个字节是制造商id。。所以写在卡上的数字应该是CE 75 4C或13530444 convertedHi hovo,你是如何用CE 75 4C ty0xCE754C=13530444获得13530444的你是我的英雄,+1你可以在这里找到一个ASCII表:供你手动计算。前两个字节是制造商id。。所以写在卡片上的号码应该是CE
75 4C或13530444 convertedHi hovo,你是如何用CE 75 4C ty0xCE754C=13530444获得13530444的你是我的英雄, +1@dda您编辑了我的回答,说原始代码是用Arduino编写的-阿法伊克·阿杜伊诺是唯一的硬件-为Arduino编写的代码是C/C++。@dda您编辑了我的回答,说原始代码是用Arduino编写的-阿法伊克·阿杜伊诺是唯一的硬件-为Arduino编写的代码是C/C++。
//assume you have checksum as int and code as int array. it will overflow if bytes are used like above example
public void run() {
  Log.d(TAG, "BEGIN mConnectedThread");
  byte[] buffer = new byte[1024];
  int bytes;
  // Keep listening to the InputStream while connected
  while (true) {
    Log.d(TAG, "Running");
    try {
      // Read from the InputStream
      bytes = mmInStream.read(buffer);
      for (int i = 0; i < bytes; i++) {
        Log.d(TAG, "Reading: " + i + " of " + bytes + " from input stream");
        byte b = buffer[i];
        try {
          if(bytesread >= 0) {
            //just printing ASCII
            char printableB = (char) b;
            if (b < 32 || b > 126) printableB = ' ';
            Log.d(TAG, "'" + Character.toString(printableB) + "' (" + Integer.toString(b) + ")");
            if((b == 0x0D)||(b == 0x0A)||(b == 0x03)||(b == 0x02)) {
              // if header or stop bytes before the 10 digit reading
              Log.e(TAG, i + " Unexpected header while processing character " + Integer.toString(b));
            } else {
              // Do ASCII/Hex conversion
              if ((b >= '0') && (b <= '9')) {
                b = (byte) (b - '0');
              } else if ((b >= 'A') && (b <= 'F')) {
                b = (byte) (10 + b - 'A');
              }
              if ((bytesread & 1) == 1) {
                //if isOdd(bytesread)
              // make some space for this hex-digit by shifting the previous hex-digit with 4 bits to the left:
              code[bytesread >> 1] = (b | (tempbyte << 4));
              if (bytesread >> 1 != 5) {
                // If we're not at the checksum byte,
                checksum ^= code[bytesread >> 1];
                // Calculate the checksum... (XOR)
              }
            } else {
              // Store the first hex digit first
              tempbyte = b; 
            }
          }
          bytesread++;
        } else if(b == 2) {
          bytesread = 0;
          Log.d(TAG, "Header found!");
        }
        if(bytesread == 12) {
          String check = (code[5] == checksum ? "-passed" : "-error");
          String r = "";
          for(int j = 0; j < 5; j++){
            r += Integer.toString(code[i]);
          }
          Log.d(TAG, "Check:" + Integer.toString(code[5]) + check);
          init();
        } else if(bytesread > 12){
          Log.e(TAG, "Too many bytes!");
        }
      } catch (Exception e) {
        Log.e(TAG, i + " Exception while processing character " + Integer.toString(b), e);
      }
    }
    String a = buffer.toString();
    a = "";
  } catch (IOException e) {
    Log.e(TAG, "disconnected", e);
    connectionLost();
    break;
  }
}
Log.i(TAG, "END mConnectedThread");
}