新手请问一个go语言的信息隐藏实验

z769018860 · 2017-06-02 12:19:24 · 2457 次点击 · 大约8小时之前 开始浏览    置顶
这是一个创建于 2017-06-02 12:19:24 的主题,其中的信息可能已经有所发展或是发生改变。

大体框架有了但是缺一些核心代码 刚刚接触go语言感觉还不太能读懂这个框架的意思 http://csintro.ucas.ac.cn/static/code_project/hide.go

主要是中间需要填写四个函数 第一个_4byte2int不太明白是什么作用,应该怎么写 后面有两个函数给了伪代码,

Procedure HideText (pixel_array) {
    content = read all bytes of text file
    length = length of the content
    insert_data(length, pixel_array[0:16], 16)
    for i = 0 to len(content)-1 {
        v = content[i]
        // the offset of pixel array
        offset = 16+i*4
        // the corresponding slice that will be used
        insert_data(byte, pixel_array[offset: offset+4], 4)
    }
}
// hide the integer data into the byte slice
// using the first n bytes of the slice
Procedure insert_data(data, byte_slice, n) {
    for i = 0 to n-1 {
        _2bit = data & 0x3
        byte_slice[i] = byte_slice[i] & 0xFC
        byte_slice[i] = byte_slice[i] | _2bit
        data = data >> 2
    }
}
Procedure ShowText (pixel_array) {
    length = restore_data(pixel_array[0:16], 16)
    content = create a byte slice with the specific length
    for i = 0 to length-1 {
        // the offset of pixel array
        offset = 16+i*4
        // the corresponding slice that will be translated to a byte
        content[i] = restore_data(pixel_array[offset: offset+4], 4)
    }
}
// restore the integer data from the byte slice
// using the first n bytes of the slice
Procedure restore_data(byte_slice, n) {
    data = 0
    for i = n-1 to 0 {
        _2bit = byte_slice[i] & 0x3
        data = data << 2
        data = data | _2bit
    }
}

对应的是后两个函数,但是伪代码里面调用函数时的变量类型都不同(:зゝ∠)然后就又不知道怎么下手了


有疑问加站长微信联系(非本文作者)

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

2457 次点击  
加入收藏 微博
5 回复  |  直到 2018-06-28 21:07:24
polaris
polaris · #1 · 8年之前

这么长一大段,也不说自己哪个地方不懂

z769018860
z769018860 · #2 · 8年之前
polarispolaris #1 回复

这么长一大段,也不说自己哪个地方不懂

中间要写四个小程序,第一个_4byte2int不太明白是什么作用应该怎么写

Cynhard
Cynhard · #3 · 8年之前

_4byte2int将byte切片转换为int,属于底层操作,需要用到Go低级编程的知识。

func _4byte2int(bs []byte) int {
    return *(*int)(unsafe.Pointer(&bs))
}
z769018860
z769018860 · #4 · 8年之前
CynhardCynhard #3 回复

_4byte2int将byte切片转换为int,属于底层操作,需要用到[Go低级编程](http://blog.csdn.net/u011304970/article/details/69908641#lowLevel)的知识。 ```go func _4byte2int(bs []byte) int { return *(*int)(unsafe.Pointer(&bs)) } ```

那请问下下面那个getpartsofbmp的函数要怎么调用_4byte2int,为什么要把byte转化成Int

ChemistryKing
ChemistryKing · #5 · 7年之前

果壳的?

添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传