Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
xfgryujk committed Jul 19, 2018
2 parents 5e7033a + 3c648a1 commit 613e966
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 23 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ javascript:fetch('https://raw.githubusercontent.com/xfgryujk/weibo-img-crypto/ma
## 算法说明
加密的原理是把 RGB 数据随机移动到一个新位置,所以加密解密时的随机种子必须一样。默认的随机种子是 `114514`,可以在设置界面修改随机种子

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

## 兼容性
目前不支持 GIF 图,以后可能支持
Expand Down
Binary file modified demo/decrypted.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified demo/encrypted.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
36 changes: 17 additions & 19 deletions src/codec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {Notification} from 'element-ui'
import {RandomSequence} from './random'
import {getConfig} from './config'
import {splitChannels, mergeChannels, gaussianBlur, medianBlur} from './imgproc'
import {gaussianBlur, medianBlur} from './imgproc'

let canvas = document.createElement('canvas')
let ctx = canvas.getContext('2d')
Expand Down Expand Up @@ -153,18 +153,18 @@ class MoveRgbCodec extends Codec {
}
Codec._codecClasses.MoveRgbCodec = MoveRgbCodec

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

decrypt () {
return this._doCommon((result, iChannel, blockX, blockY, newBlockX, newBlockY) =>
this._copyBlock(iChannel, result, blockX, blockY, this._imgData, newBlockX, newBlockY)
return this._doCommon((result, blockX, blockY, newBlockX, newBlockY) =>
this._copyBlock(result, blockX, blockY, this._imgData, newBlockX, newBlockY)
)
}

Expand All @@ -174,25 +174,23 @@ class Move8x8BlockCodec extends Codec {
let blockHeight = Math.floor(this._imgData.height / 8)
let result = ctx.createImageData(blockWidth * 8, blockHeight * 8)
let seq = new RandomSequence(blockWidth * blockHeight, getConfig().randomSeed)
for (let iChannel = 0; iChannel < 4; iChannel++) {
for (let blockY = 0; blockY < blockHeight; blockY++) {
for (let blockX = 0; blockX < blockWidth; blockX++) {
let index = seq.next()
let newBlockX = index % blockWidth
let newBlockY = Math.floor(index / blockWidth)
handleCopy(result, iChannel, blockX, blockY, newBlockX, newBlockY)
}
for (let blockY = 0; blockY < blockHeight; blockY++) {
for (let blockX = 0; blockX < blockWidth; blockX++) {
let index = seq.next()
let newBlockX = index % blockWidth
let newBlockY = Math.floor(index / blockWidth)
handleCopy(result, blockX, blockY, newBlockX, newBlockY)
}
}
return result
}

_copyBlock (iChannel, dstImgData, dstBlockX, dstBlockY, srcImgData, srcBlockX, srcBlockY) {
let iDstStart = (dstBlockY * dstImgData.width + dstBlockX) * 8 * 4 + iChannel
let iSrcStart = (srcBlockY * srcImgData.width + srcBlockX) * 8 * 4 + iChannel
_copyBlock (dstImgData, dstBlockX, dstBlockY, srcImgData, srcBlockX, srcBlockY) {
let iDstStart = (dstBlockY * dstImgData.width + dstBlockX) * 8 * 4
let iSrcStart = (srcBlockY * srcImgData.width + srcBlockX) * 8 * 4
for (let y = 0; y < 8; y++) {
for (let x = 0; x < 8; x++) {
dstImgData.data[iDstStart + x * 4] = srcImgData.data[iSrcStart + x * 4]
for (let i = 0; i < 8 * 4; i++) {
dstImgData.data[iDstStart + i] = srcImgData.data[iSrcStart + i]
}
iDstStart += dstImgData.width * 4
iSrcStart += srcImgData.width * 4
Expand Down
4 changes: 2 additions & 2 deletions src/gui/gui.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<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 ARGB块" value="Move8x8BlockCodec"></el-option>
<el-option label="随机移动8x8 像素块" value="Move8x8BlockCodec"></el-option>
</el-select>
</el-form-item>
<el-form-item label="随机种子">
Expand All @@ -50,7 +50,7 @@
使用方法:上传图片时自动加密,在图片上点击鼠标右键自动解密。加密解密时的算法、随机种子必须一致。如果加了水印,解密后的图片会有杂色,开启自动去水印会在上传时临时关闭你的水印。一般情况下不建议添加解密后处理,如果你实在忍受不了解密后的噪声再添加
</p>
<p>
算法说明:推荐使用随机移动 8x8 ARGB 块算法,这样不会出现有损压缩再解密造成的高频噪声。随机移动 RGB 值算法会出现有损压缩再解密造成的高频噪声。至于反色算法只是作者平时用来看某些博主的色图用的,不算加密
算法说明:推荐使用随机移动 8x8 像素块算法,这样不会出现有损压缩再解密造成的高频噪声。随机移动 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
2 changes: 1 addition & 1 deletion weibo-img-crypto.js

Large diffs are not rendered by default.

0 comments on commit 613e966

Please sign in to comment.