Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
xfgryujk committed Mar 16, 2019
2 parents 1e6f54e + ad720eb commit dc9b5f2
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 26 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ javascript:fetch('https://raw.githubusercontent.com/xfgryujk/weibo-img-crypto/ma
首先安装 [Tampermonkey](http://tampermonkey.net/) 浏览器扩展,然后[去 Greasy Fork 添加 weibo-img-crypto 脚本](https://greasyfork.org/zh-CN/scripts/370359-weibo-img-crypto)。这样访问微博时会自动执行方法 1 的代码

## 算法说明
加密的原理是把 RGB 数据随机移动到一个新位置,所以加密解密时的随机种子必须一样。默认的随机种子是 `114514`,可以在设置界面修改随机种子
加密的原理是把像素块或 RGB 数据随机移动到一个新位置,所以加密解密时的随机种子必须一样。默认的随机种子是 `114514`,可以在设置界面修改随机种子

推荐使用`随机移动 8x8 像素块`算法,这样不会出现有损压缩再解密造成的高频噪声。`随机移动 RGB 值`算法会出现有损压缩再解密造成的高频噪声。至于反色算法~~只是作者平时用来看某些博主的色图用的~~,不算加密
推荐使用`块随机置乱`算法,这样不会出现有损压缩再解密造成的高频噪声。`RGB随机置乱`算法会出现有损压缩再解密造成的高频噪声。至于反色算法~~只是作者平时用来看某些博主的色图用的~~,不算加密

## 兼容性
目前不支持 GIF 图,以后可能支持
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "weibo-img-crypto",
"version": "1.3.3",
"version": "1.4.0",
"description": "Automatically encrypt images before uploading them to Weibo.",
"author": "xfgryujk <xfgryujk@126.com>",
"private": true,
Expand Down
61 changes: 47 additions & 14 deletions src/codec.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,23 +100,23 @@ Codec.createCodec = function (name, imgData) {
}

// 反色
class InvertRgbCodec extends Codec {
encrypt () { return this._invertColor(this._imgData) }
decrypt () { return this._invertColor(this._imgData) }
_invertColor (imgData) {
let data = imgData.data
class InvertCodec extends Codec {
encrypt () { return this._invertColor() }
decrypt () { return this._invertColor() }
_invertColor () {
let data = this._imgData.data
for (let i = 0; i < data.length; i += 4) {
data[i] = ~data[i] & 0xFF
data[i + 1] = ~data[i + 1] & 0xFF
data[i + 2] = ~data[i + 2] & 0xFF
}
return imgData
return this._imgData
}
}
Codec._codecClasses.InvertRgbCodec = InvertRgbCodec
Codec._codecClasses.InvertCodec = InvertCodec

// 将RGB值随机移动
class MoveRgbCodec extends Codec {
// RGB随机置乱
class ShuffleRgbCodec extends Codec {
encrypt () {
let data = this._imgData.data
let nRgbs = data.length / 4 * 3
Expand Down Expand Up @@ -155,11 +155,11 @@ class MoveRgbCodec extends Codec {
return this._imgData
}
}
Codec._codecClasses.MoveRgbCodec = MoveRgbCodec
Codec._codecClasses.ShuffleRgbCodec = ShuffleRgbCodec

// 将8x8像素块随机移动
// 由于JPEG是分成8x8的小块在块内压缩,分成8x8小块处理可以避免压缩再解密造成的高频噪声
class Move8x8BlockCodec extends Codec {
// 块随机置乱
// 由于JPEG是分成8x8的块在块内压缩,分成8x8块处理可以避免压缩再解密造成的高频噪声
class ShuffleBlockCodec extends Codec {
encrypt () {
return this._doCommon((result, blockX, blockY, newBlockX, newBlockY) =>
this._copyBlock(result, newBlockX, newBlockY, this._imgData, blockX, blockY)
Expand Down Expand Up @@ -201,4 +201,37 @@ class Move8x8BlockCodec extends Codec {
}
}
}
Codec._codecClasses.Move8x8BlockCodec = Move8x8BlockCodec
Codec._codecClasses.ShuffleBlockCodec = ShuffleBlockCodec

// 半反色
class HalfInvertCodec extends Codec {
encrypt () { return this._halfInvertColor() }
decrypt () { return this._halfInvertColor() }

_halfInvertColor () {
let invertFirst = true
for (let y = 0; y < this._imgData.height; y += 8) {
let height = Math.min(8, this._imgData.height - y)
for (let x = invertFirst ? 0 : 8; x < this._imgData.width; x += 16) {
let width = Math.min(8, this._imgData.width - x)
this._invertColor(x, y, width, height)
}
invertFirst = !invertFirst
}
return this._imgData
}

_invertColor (x, y, width, height) {
let data = this._imgData.data
let iStart = (y * this._imgData.width + x) * 4
for (let y = 0; y < height; y++) {
for (let i = 0; i < width * 4; i += 4) {
data[iStart + i] = ~data[iStart + i] & 0xFF
data[iStart + i + 1] = ~data[iStart + i + 1] & 0xFF
data[iStart + i + 2] = ~data[iStart + i + 2] & 0xFF
}
iStart += this._imgData.width * 4
}
}
}
Codec._codecClasses.HalfInvertCodec = HalfInvertCodec
2 changes: 1 addition & 1 deletion src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export function getConfig () {
enableEncryption: true,
enableDecryption: true,
noWaterMark: true,
codecName: 'Move8x8BlockCodec',
codecName: 'ShuffleBlockCodec',
randomSeed: DEFAULT_SEED,
postProcess: ''
}, JSON.parse(window.localStorage.wbImgCryptoConfig || '{}'))
Expand Down
11 changes: 6 additions & 5 deletions src/gui/gui.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</a>
</el-tooltip>

<el-dialog title="weibo-img-crypto v1.3.3" :visible.sync="dialogVisible">
<el-dialog title="weibo-img-crypto v1.4.0" :visible.sync="dialogVisible">
<el-tabs>
<el-tab-pane label="基础">
<el-form label-width="100px">
Expand All @@ -26,9 +26,10 @@
<el-form label-width="100px">
<el-form-item label="算法">
<el-select v-model="form.codecName" placeholder="">
<el-option label="反色" value="InvertRgbCodec"></el-option>
<el-option label="随机移动RGB值" value="MoveRgbCodec"></el-option>
<el-option label="随机移动8x8像素块" value="Move8x8BlockCodec"></el-option>
<el-option label="反色" value="InvertCodec"></el-option>
<el-option label="RGB随机置乱" value="ShuffleRgbCodec"></el-option>
<el-option label="块随机置乱" value="ShuffleBlockCodec"></el-option>
<el-option label="半反色" value="HalfInvertCodec"></el-option>
</el-select>
</el-form-item>
<el-form-item label="随机种子">
Expand All @@ -54,7 +55,7 @@
使用方法:上传图片时自动加密,在图片上点击鼠标右键自动解密。加密解密时的算法、随机种子必须一致。如果加了水印,解密后的图片会有杂色,开启自动去水印会在上传时临时关闭你的水印。一般情况下不建议添加解密后处理,如果你实在忍受不了解密后的噪声再添加
</p>
<p>
算法说明:推荐使用随机移动 8x8 像素块算法,这样不会出现有损压缩再解密造成的高频噪声。随机移动 RGB 值算法会出现有损压缩再解密造成的高频噪声。至于反色算法只是作者平时用来看某些博主的色图用的,不算加密
算法说明:推荐使用块随机置乱算法,这样不会出现有损压缩再解密造成的高频噪声。RGB随机置乱算法会出现有损压缩再解密造成的高频噪声。至于反色算法只是作者平时用来看某些博主的色图用的,不算加密
</p>
<p>
推荐使用<a href="https://greasyfork.org/zh-CN/scripts/370359-weibo-img-crypto" target="_blank">油猴脚本</a>,可以最方便地使用 weibo-img-crypto,详情见 <a href="https://github.com/xfgryujk/weibo-img-crypto" target="_blank">GitHub 库 readme</a>
Expand Down
6 changes: 3 additions & 3 deletions weibo-img-crypto.js

Large diffs are not rendered by default.

0 comments on commit dc9b5f2

Please sign in to comment.