Skip to content

Commit

Permalink
Minor issue fixes. (#6)
Browse files Browse the repository at this point in the history
* Fix a logic mistake when encrypting links.

* Update Readme.

* Minor fix.
  • Loading branch information
SheepChef authored Oct 30, 2024
1 parent 287c35c commit 0ad5340
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 23 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ Abracadabra 还在积极开发中,这里是一些注意事项。
项目在 Windows 11 和 Ubuntu 22.04 LTS 上通过了编译测试。
在嵌入式平台(armv7a, armv8a)上通过了运行测试。
### 已知问题
#### 处理文件耗时指数级增加
Expand All @@ -81,7 +83,7 @@ Abracadabra 还在积极开发中,这里是一些注意事项。
原则上不能以牺牲随机性为代价换取执行速度,且本项目之目的并不是将文件转换为上百万个汉字,故搁置该问题。
小于 100kb 的文件均能在可控时间内得到处理。
小于 100kb 的文件均能在可控时间内得到处理。
#### 密本随机性不足
Expand All @@ -97,6 +99,10 @@ Abracadabra 还在积极开发中,这里是一些注意事项。
- [cppcodec](https://github.com/tplgy/cppcodec)
- [CLI11](https://github.com/CLIUtils/CLI11)
另外,请确保您的环境中安装了 C++11 标准库。
本项目并不复杂,推荐直接用指令调用 g++ 进行构建。如果您愿意,也可以尝试 CMake。
## 细节
### 加密实现
Expand Down
23 changes: 12 additions & 11 deletions src/abracadabra.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,8 @@ string enMap(PreCheckResult input,bool forceLink,bool forceBase64,bool forceDire
}
}
else if(q==1){ // 第二次大循环插入加密标志位


vector<int> AvailPos;
AvailPos.resize(max(PosToInset.size(),Avoid.size()));

Expand Down Expand Up @@ -559,18 +561,17 @@ string GetLinkCryptedText(string text){//查表,检查是否有任何预配置
s1 = el.key();
if(s.find(s1) != string::npos){//找到关键词
el.value().get_to(CipherArray);

//返回密本中的随机字符
RandIndex = dist(mt_r) % CipherArray.size(); //随机获取一个下标
int i = 0 ;
for (auto it : Map_Obj["link"][s1]){
if (i == RandIndex){//找到下标
s2 = (string)it;
break;
}
i++;
}
while(s.find(s1)<s.size()){
//返回密本中的随机字符
RandIndex = dist(mt_r) % CipherArray.size(); //随机获取一个下标
int i = 0 ;
for (auto it : Map_Obj["link"][s1]){
if (i == RandIndex){//找到下标
s2 = (string)it;
break;
}
i++;
}
int pos = s.find(s1);
s.replace(pos, s1.size(), s2);
}
Expand Down
21 changes: 10 additions & 11 deletions src/abracadabra_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -558,18 +558,17 @@ string GetLinkCryptedText(string text){//查表,检查是否有任何预配置
s1 = el.key();
if(s.find(s1) != string::npos){//找到关键词
el.value().get_to(CipherArray);

//返回密本中的随机字符
RandIndex = dist(mt_r) % CipherArray.size(); //随机获取一个下标
int i = 0 ;
for (auto it : Map_Obj["link"][s1]){
if (i == RandIndex){//找到下标
s2 = (string)it;
break;
}
i++;
}
while(s.find(s1)<s.size()){
//返回密本中的随机字符
RandIndex = dist(mt_r) % CipherArray.size(); //随机获取一个下标
int i = 0 ;
for (auto it : Map_Obj["link"][s1]){
if (i == RandIndex){//找到下标
s2 = (string)it;
break;
}
i++;
}
int pos = s.find(s1);
s.replace(pos, s1.size(), s2);
}
Expand Down

0 comments on commit 0ad5340

Please sign in to comment.