西维蜀黍

【Hardware】ID 卡和 IC 卡

IC 卡

高频(High frequency)是指频带由3MHz到30MHz的无线电波,然而常用的RFID使用的高频频段为13.56MHz。

IC卡全称集成电路卡(Integrated Circuit Card),又称智能卡(Smart Card)。可读写,容量大,有加密功能,数据记录可靠,使用更方便,如一卡通系统,消费系统等,目前主要有PHILIPS的Mifare系列卡(也称为 M1 Card)。

类别

类型 频率 特性
Mifare S50(简称M1) 高频 最常见的卡,每张卡有独一无二的UID号,可保存修改数据,常见学生卡,饭卡,公交卡,门禁卡
Mifare UltraLight(简称M0) 高频 低成本卡,出厂固化UID,可储存修改数据,常见地铁卡,公交卡
Mifare UID(简称UID卡) 高频 M1卡的变异版本,可修改UID,国外叫做中国魔术卡,可以用来克隆M1 S50的数据

HID

  • iCLASS® Seos
  • iCLASS SE®
  • iCLASS®
  • Crescendo®
  • HID Proximity

MIFARE Classic 1K(简称 M1 卡)

目前最常见的高频卡,也是我们口中俗称的IC卡。

M1卡可储存的数据大小为1K,分为16个扇区(sector),每个扇区分4个块(block),每个块为16个字节,以块为存取单位。每个扇区都有独立的一组密码(key A and key B)及访问控制。

每张卡有唯一的一个32位的序列号。每个扇区的第0、1、2块为可用数据区,用来存储数据,第3块为控制块,包括了密码A(key A)、存取控制(Access Bits)、密码B(key B)。

每张卡的第0扇区的第0块用来存放厂商代码(Manufacturer data, including UID),contains the UID, BCC, SAK, ATQA and Manufacturer data,在通常情况下,不可更改。

中间4字节控制字是管理密码权限,用来设置A密码和B密码的功能。默认不修改的时候,可以用A密码读写所有数据。A密码不可读出,B密码可以用A密码读出。密码不一定可以读取,由控制字决定。

M1 UID卡/普通复制卡

M1 UID卡是针对M1 S50卡特制的变种卡,用起来和M1 S50完全一样,只是多了一个功能,可以重复擦写所有扇区,包括0扇区块。因此UID号也可以随意修改,厂家信息也可以随意修改。

CUID卡/升级复制卡

CUID卡是针对FUID卡做的优化。CUID卡可以重复修改0块,但是它和UID卡的区别是,UID卡是通过指令修改0块,CUID使用的是常规密码验证的方法写0块,其他扇区和标准M1卡相同。缺点是,有可能会被检测出来,而且如果不小心写错了UID号的校验位导致无法读卡,没办法修复只能报废。

FUID卡/高级复制卡

FUID卡是针对UID卡做的优化。新的读卡系统,通过检测卡片对特殊指令的回应,可以检测出UID卡,因此可以来拒绝UID卡的访问,来达到屏蔽复制卡的功能。

FUID的0扇区可以被修改,但只可以修改一次,写错也没办法更改,因而不能重复利用。

但是修改后和M1卡完全一样,很难被屏蔽检测。

UFUID卡/高级复制卡 - 推荐

就是UID和FUID的合成卡,需要封卡操作时,封卡之后变成M1卡,不封卡时就是UID卡。

破解

arc122u只能读取和修改高频卡(IC 卡),有点不足

ID卡

ID卡全称身份识别卡(Identification Card),是一种不可写入的感应卡,含固定的编号,主要有台湾SYRIS的EM格式,美国的HID、TI 和 MOTOROLA等各类ID卡。

ID卡属于大家常说的低频卡,一般大部分情况下作为门禁卡或者大部分大学里使用的饭卡,一般为厚一些的卡,是只读的,卡里面只保存有一串唯一的数字序号ID,可以把这串数字理解为你的身份证号,刷卡的时候,读卡器只能读到ID号,然后通过跟后台数据库进行匹配,如果是门禁卡,那么数据库里面就是存在这样的ID号,如果匹配上门就开了,匹配不上门就开不了。

如果是学校的饭卡,刷卡的时候,实际上操作的是你对应ID号相关的数据库中的数据。ID卡本身不存在任何其他数据,所以,学校使用的ID卡饭卡,只能复制卡,刷别人的钱(数据库中的钱),再没有其他办法。

如果卡上写着 HID,这张卡也可能是 IC 卡(see https://www.hidglobal.com/product-display/cards-and-credentials/iclass)。

由此可以看出,ID卡是可加密的存储卡、ID卡是只读的低频卡。

CPU卡

CPU card chip is a microprocessor, If you want to achieve more advanced features and the security level is particularly high, its function is equivalent to a microcomputer. CPU cards can be applied to many fields such as finance, insurance, traffic police, and government industries etc.

有操作系统,可存储数据,也有自己的ID号,CPU卡发一串数据给设备,设备与SAM卡进行运算,设备再发一串数据回CPU卡确认,然后进行交易或身份认证;跟M1卡的区别在于一个算法在空中,一个算法在设备里面;无论是卡商,设备商,运营商,都不知道其中的算法,所以这个系统的安全性会高很多。

  ...


【MySQL】数据类型(Data Types)

数字类型 (Numeric Data Types)

Integer Type (Exact Value)

Difference is in range and storage. Choose unsigned to maximise the maximum value if not using negative values.

  • TINYINT:一个微小整数,支持 -128到127(SIGNED),0到255(UNSIGNED),需要1个字节存储
  • SMALLINT:一个小整数,支持 -32768到32767(SIGNED),0到65535(UNSIGNED),需要2个字节存储
  • MEDIUMINT:一个中等整数,支持 -8388608到8388607(SIGNED),0到16777215(UNSIGNED),需要3个字节存储
  • INT:一个整数,支持 -2147493648到2147493647(SIGNED),0到4294967295(UNSIGNED),需要4个字节存储
  • INTEGER:同INT
  • BIGINT:一个大整数,支持 -9223372036854775808到9223372036854775807(SIGNED),0到18446744073709551615(UNSIGNED),需要8个字节存储

注意,默认为SIGNED,只有显式地声明为UNSIGNED,才是UNSIGNED。

Type Storage (Bytes) Minimum Value Signed Minimum Value Unsigned Maximum Value Signed Maximum Value Unsigned
TINYINT 1 -128 0 127 255
SMALLINT 2 -32768 0 32767 65535
MEDIUMINT 3 -8388608 0 8388607 16777215
INT 4 -2147483648 0 2147483647 4294967295
BIGINT 8 -2$^{63}$ 0 2$^{63}$-1 2$^{64}$-1

See https://dev.mysql.com/doc/refman/5.6/en/integer-types.html for more details.

  ...


【MySQL】MySQL 中的各种数据类型转换

Int -> varcher

将Int 转为varchar可以用 concat() 函数,比如 concat(8,’0′) 得到字符串 ’80′。

delete from core_channel;


drop procedure if exists insert_channel;

delimiter //

CREATE procedure insert_channel()
wholeblock:BEGIN
  declare str VARCHAR(255) default '';
  declare x INT default 0;
  SET x = 1;

  WHILE x <= 10 DO
    insert into core_channel (name) values (CONCAT("name",x));
    SET x = x + 1;
  END WHILE;

  select str;
END//

call insert_channel	();
  ...


【Golang】Golang 命令

Golang 命令

$ go
Go is a tool for managing Go source code.

Usage:

	go <command> [arguments]

The commands are:

	bug         start a bug report
	build       compile packages and dependencies
	clean       remove object files and cached files
	doc         show documentation for package or symbol
	env         print Go environment information
	fix         update packages to use new APIs
	fmt         gofmt (reformat) package sources
	generate    generate Go files by processing source
	get         add dependencies to current module and install them
	install     compile and install packages and dependencies
	list        list packages or modules
	mod         module maintenance
	run         compile and run Go program
	test        test packages
	tool        run specified go tool
	version     print Go version
	vet         report likely mistakes in packages

Use "go help <command>" for more information about a command.

Additional help topics:

	buildmode   build modes
	c           calling between Go and C
	cache       build and test caching
	environment environment variables
	filetype    file types
	go.mod      the go.mod file
	gopath      GOPATH environment variable
	gopath-get  legacy GOPATH go get
	goproxy     module proxy protocol
	importpath  import path syntax
	modules     modules, module versions, and more
	module-get  module-aware go get
	module-auth module authentication using go.sum
	module-private module configuration for non-public modules
	packages    package lists and patterns
	testflag    testing flags
	testfunc    testing functions

Use "go help <topic>" for more information about that topic.
  ...


【Golang】指针(Pointers)

Background

Although Go absorbs many features from all kinds of other languages, Go is mainly viewed as a C family language. One evidence is Go also supports pointers. Go pointers and C pointers are much similar in many aspects, but there are also some differences between Go pointers and C pointers. This article will list all kinds of concepts and details related to pointers in Go.

  ...


【Golang】类型转换 - 获取变量类型

如果某个函数的入参的类型是 interface{},有下面几种方法可以获取入参的类型:

获取入参类型的方法

1 反射

import (
    "reflect"
    "fmt"
)
func main() {
    v := "hello world"
    fmt.Println(typeof(v))
}
func typeof(v interface{}) string {
    return reflect.TypeOf(v).String()
}

Example

其实,fmt.Sprintf("%T") 底层也是用反射实现的:

func (p *pp) printArg(arg interface{}, verb rune) {
	...
	// Special processing considerations.
	// %T (the value's type) and %p (its address) are special; we always do them first.
	switch verb {
	case 'T':
		p.fmt.fmtS(reflect.TypeOf(arg).String())
		return
  ...
  }
}  

Usage:

import "fmt"
func main() {
    v := "hello world"
    fmt.Println(typeof(v))
}
func typeof(v interface{}) string {
    return fmt.Sprintf("%T", v)
}
  ...


【Linux】CentOS 安装Docker

卸载旧版本

较旧的 Docker 版本称为 docker 或 docker-engine 。如果已安装这些程序,请卸载它们以及相关的依赖项。

$ sudo yum remove docker \
         docker-client \
         docker-client-latest \
         docker-common \
         docker-latest \
         docker-latest-logrotate \
         docker-logrotate \
         docker-engine
  ...


【Protobuf】Protocol Buffers 入门

Protocol Buffers (Protobuf)

Protocol Buffers (Protobuf) is a free and open source cross-platform library used to serialize structured data. It is useful in developing programs to communicate with each other over a network or for storing data.

The method involves an interface description language that describes the structure of some data and a program that generates source code from that description for generating or parsing a stream of bytes that represents the structured data.

  ...


【Golang】使用 - 上传文件

单文件上传

我们使用multipart/form-data格式上传文件,利用c.Request.FormFile解析文件。

// HandleUploadFile 上传单个文件
func HandleUploadFile(c *gin.Context) {
	file, header, err := c.Request.FormFile("file")
	if err != nil {
		c.JSON(http.StatusBadRequest, gin.H{"msg": "文件上传失败"})
		return
	}

	content, err := ioutil.ReadAll(file)
	if err != nil {
		c.JSON(http.StatusBadRequest, gin.H{"msg": "文件读取失败"})
		return
	}

	fmt.Println(header.Filename)
	fmt.Println(string(content))
	c.JSON(http.StatusOK, gin.H{"msg": "上传成功"})
}
  ...


【Raspberry Pi】树莓派玩耍

查看树莓派系统的位数

安装软件的时候想查看树莓派系统是32位还是64位就出现了以下的操作,具体命令及作用如下:

getconf LONG_BIT        # 查看系统位数
uname -a            # kernel 版本
/opt/vc/bin/vcgencmd  version   # firmware版本
strings /boot/start.elf  |  grep VC_BUILD_ID    # firmware版本
cat /proc/version       # kernel
cat /etc/os-release     # OS版本资讯
cat /etc/issue          # Linux distro 版本
cat /etc/debian_version     # Debian版本编号

虽然树莓派3b的硬件支持64位的系统,但是官方的系统还是32位的,主要应该是为了兼容之前的硬件。

  ...