# Trojan Source
[trojan-source paper](https://trojansource.codes/trojan-source.pdf)
[trojan-source website](https://trojansource.codes/)
[trojan-source github](https://github.com/nickboucher/trojan-source)
## Methodology
不同地區的文字讀寫方向不太一樣,英文、俄文都是左到右,希伯來文和阿拉伯文是右到左,為了支援這種情況,Unicode 用 bidiretional algorithm 來處理
bidirectional 的操作可以看以下表格:

以下紀錄幾個比較重要的重點
### Reordering
其中 LRI 和 RLI 就是決定用哪種方向來讀取字串,並且最後用 PDI 閉合,如果碰到換行也會自動閉合
ex:
`RLI a b c PDI` -> `c b a`
要特別注意,如果是括號類型的也會變成相對應的左右括號,像是 `{` 變成 `}`
### Isolating
isolating 是指被包住的 group 可以視做一個實體,上面例子中的 RLI 和 PDI 中間的就是一個 group 且 bidirectional algorithm 支援 nested:
`RLI LRI a b c PDI LRI d e f PDI PDI` -> `d e f a b c`
拆解:
1. `LRI a b c PDI` -> `a b c` ,這樣就是一個 group
2. `LRI d e f PDI` -> `d e f`
3. `RLI group1 group2 PDI` -> `group2 group1` -> `d e f a b c`
### Syntax Adherence
如果直接把 unicode 塞在 code 裏面,很大機會會被 compiler 當成一個 token 並送去 parse ,這樣很容易產生 syntax error ,不過可以放在 string 或 comment 裏面
## Example
眼睛看到的
```c=
#include <stdio.h>
#include <stdbool.h>
int main() {
bool isAdmin = false;
/* } if (isAdmin) begin admins only */
printf("You are admin");
/* end admin only { */
}
```
實際上
```c=
#include <stdio.h>
#include <string.h>
int main() {
bool isAdmin = false;
/* RLO } LRI if (isAdmin)PDI LRI begin admins only */
printf("You are admin");
/* end admin only RLO { LRI*/
}
```
line 6 可以分成:`}`, `if (isAdmin)` 和 `begin admins only */` 三組,經過 RLO 兩組會變換順序,加上前面的 RLO 則 line 6 變成: `/* group3 group2 group 1` 也就是
`/* begin admins only */ if (isAdmin) {`
line 8 同理,把 `{` 用 RLO 轉成 `}`
實際執行:

目前實際測試過 vscode 呈獻的效果跟 hackmd 的差不多,看起來很像 highligh 壞掉 XD 如果是用 github raw mode 去看就比較正常(但看起來很像沒排版)

但 github 會提醒:

## Homoglyph Attacks
這是用不同字型來命名 function name , paper 中是以 Latin H 和 Cyrillic
Н 當作例子

## Input unicode in vim
1. insert mode
2. `ctrl` + `V` (V must be upper case, so need to press shift at same time)
3. `u 4digit hex`, ex: `u2026`
[inserting-unicode-characters-in-vim](https://x-team.com/blog/inserting-unicode-characters-in-vim/)
## 表格
