# Bitcoin and Cryptocurrency Technologies 学习笔记 （week 1)

in cn •  2 years ago  (edited)

## 一、哈希函数

Hash函数指可以将任意长度的数据映射到有限长度的域上，比特币使用SHA-256作为Hash 函数，Hash函数具有以下三特性

### 2. Hiding

Hash函数为H, 给出H(x), 无法反推出 x.

## 二、公钥私钥 + 数字签名

### 2. 公私钥产生

ECC 比 RSA 性能好，强度高，未来可能成为唯一的产生算法，加密货币都是使用ECC

### 3. 数字签名

``````(private_key, public_key) = generateKeys()

signature = sign( private_key, message)

isValid = verify(pubic_key, message, signature)

``````

## 三、区块链 + Merkle 树

### 2. Merkle 树

Merkle树是一种哈希二叉树，它用作快速归纳和校验大规模数据完整性。Merkle树根据区块中每一笔交易的Hash值自底向上构建。

### 四、 编程作业 Scrooge Coin

``````public class Transaction {

public class Input {
/** hash of the Transaction whose output is being used */
public byte[] prevTxHash;
/** used output's index in the previous transaction */
public int outputIndex;
/** the signature produced to check validity */
public byte[] signature;

public Input(byte[] prevHash, int index) {
if (prevHash == null)
prevTxHash = null;
else
prevTxHash = Arrays.copyOf(prevHash, prevHash.length);
outputIndex = index;
}

if (sig == null)
signature = null;
else
signature = Arrays.copyOf(sig, sig.length);
}
}

public class Output {
/** value in bitcoins of the output */
public double value;
/** the address or public key of the recipient */

public Output(double v, PublicKey addr) {
value = v;