Skip to content

Commit

Permalink
Merge pull request #2182 from linqining/task/task8
Browse files Browse the repository at this point in the history
task8
  • Loading branch information
uvd authored Dec 25, 2024
2 parents f0aa530 + b23984a commit cf9b2f0
Show file tree
Hide file tree
Showing 7 changed files with 197 additions and 2 deletions.
2 changes: 2 additions & 0 deletions mover/linqining/code/task8/call.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
sui client call --package 0x097a3833b6b5c62ca6ad10f0509dffdadff7ce31e1d86e63e884a14860cedc0f --module lets_move --function get_flag \
--args "SnyLUIXawx" linqining 0x19e76ca504c5a5fa5e214a45fca6c058171ba333f6da897b82731094504d5ab9 0x8 --gas-budget 3000000
37 changes: 37 additions & 0 deletions mover/linqining/code/task8/challenge/Move.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[package]
name = "challenge"
edition = "2024.beta" # edition = "legacy" to use legacy (pre-2024) Move
# license = "" # e.g., "MIT", "GPL", "Apache 2.0"
# authors = ["..."] # e.g., ["Joe Smith (joesmith@noemail.com)", "John Snow (johnsnow@noemail.com)"]

[dependencies]
Sui = { git = "https://github.com/MystenLabs/sui.git", subdir = "crates/sui-framework/packages/sui-framework", rev = "framework/testnet" }

# For remote import, use the `{ git = "...", subdir = "...", rev = "..." }`.
# Revision can be a branch, a tag, and a commit hash.
# MyRemotePackage = { git = "https://some.remote/host.git", subdir = "remote/path", rev = "main" }

# For local dependencies use `local = path`. Path is relative to the package root
# Local = { local = "../path/to" }

# To resolve a version conflict and force a specific version for dependency
# override use `override = true`
# Override = { local = "../conflicting/version", override = true }

[addresses]
challenge = "0x0"

# Named addresses will be accessible in Move as `@name`. They're also exported:
# for example, `std = "0x1"` is exported by the Standard Library.
# alice = "0xA11CE"

[dev-dependencies]
# The dev-dependencies section allows overriding dependencies for `--test` and
# `--dev` modes. You can introduce test-only dependencies here.
# Local = { local = "../path/to/dev-build" }

[dev-addresses]
# The dev-addresses section allows overwriting named addresses for the `--test`
# and `--dev` modes.
# alice = "0xB0B"

90 changes: 90 additions & 0 deletions mover/linqining/code/task8/challenge/sources/challenge.move
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@

/// Module: challenge
module challenge::challenge;

use std::ascii::{String, string};
use std::hash;
use sui::event;
use sui::bcs;
use sui::random;
use sui::random::Random;
use sui::transfer::share_object;
use std::debug::print;
use sui::address;


public struct Challenge has drop {
id:ID,
str: String,
difficulity: u64,
ture_num: u64
}




#[test]
fun test_challenge_fail() {
let challenge:Challenge = Challenge{
id: object::id_from_address(@0x19e76ca504c5a5fa5e214a45fca6c058171ba333f6da897b82731094504d5ab9),
str:std::ascii::string(b"M9[fZ#glu@qF5J8zd:m)*V87>C*\\Y"),
difficulity: 3,
ture_num: 108,
};
// let cbyte = bcs::to_bytes(&challenge);
// print(&cbyte.to_string());
let mut prefix_sum: u32 = 1;
let name = std::ascii::string(b"proof");
let borrowname = std::ascii::string(b"getproof");
let mut proof = b"1234567892";
let mut strlen:u8 =30;
let call_addr = @0xc1f4704452819f75c258fe3a01e54d6561899e3478f818625ee8be716fbdd007;
print(&call_addr.to_bytes());
while (prefix_sum!=0){
strlen = strlen+1;
let mut proof = b"SnyLUIXawx";
let mut full_proof: vector<u8> = vector::empty<u8>();
vector::append<u8>(&mut full_proof, proof);
vector::append<u8>(&mut full_proof, call_addr.to_bytes());
vector::append<u8>(&mut full_proof, bcs::to_bytes(&challenge));

let hash: vector<u8> = hash::sha3_256(full_proof);
// print(&name);
print(&proof);
prefix_sum = 0;
let mut i: u64 = 0;
while (i < challenge.difficulity) {
let borrorval = (*vector::borrow(&hash, i) as u32);

prefix_sum = prefix_sum + borrorval;
i = i + 1;
};

print(&prefix_sum);
if (prefix_sum==0){
print(&borrowname);
print(&proof);
break
}
};
return

}

fun getRandomString(laststr:vector<u8>,strLen:u8): String {
let mut gen = sui::random::new_generator_from_seed_for_testing(laststr);

let mut str_len = strLen;

let mut rand: vector<u8> = b"";
while (str_len != 0) {
let rand_num = random::generate_u8_in_range(&mut gen, 34, 126);
vector::push_back(&mut rand, rand_num);
str_len = str_len - 1;
};

string(rand)
}



Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

module challenge::challenge_tests;
8 changes: 8 additions & 0 deletions mover/linqining/code/task8/miner/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module example.com/m/v2

go 1.23.0

require (
golang.org/x/crypto v0.31.0 // indirect
golang.org/x/sys v0.28.0 // indirect
)
56 changes: 56 additions & 0 deletions mover/linqining/code/task8/miner/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package main

import (
"encoding/hex"
"fmt"
"golang.org/x/crypto/sha3"
"math/rand"
"time"
)

func main() {
preFixSum := 1

addrByte := bytesFromHex("c1f4704452819f75c258fe3a01e54d6561899e3478f818625ee8be716fbdd007")
fmt.Println(addrByte)
objByte := bytesFromHex("19e76ca504c5a5fa5e214a45fca6c058171ba333f6da897b82731094504d5ab91d4d395b665a23676c75407146354a387a643a6d292a5638373e432a5c5903000000000000006c00000000000000")
fmt.Println(objByte)

// Create a new hash & write input string
for preFixSum != 0 {
proof := getRandomString(10)
hash := sha3.New256()
_, _ = hash.Write([]byte(proof))
hash.Write(addrByte)
hash.Write(objByte)
sha3 := hash.Sum(nil)

preFixSum = 0
for i := 0; i < 3; i++ {
preFixSum = preFixSum + int(sha3[i])
}
fmt.Println(preFixSum)
if preFixSum == 0 {
fmt.Println("getproof")
fmt.Println(proof)
break
}
}
return
}

func getRandomString(n int) string {
const letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
rand.Seed(time.Now().UnixNano())
b := make([]byte, n)
for i := range b {
b[i] = letters[rand.Intn(len(letters))]
}
return string(b)
}

func bytesFromHex(hexstr string) []byte {
bytes, err := hex.DecodeString(hexstr)
fmt.Println(err)
return bytes
}
4 changes: 2 additions & 2 deletions mover/linqining/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,5 @@
- [x] flag hash : 7SW1NGXYLjPuLLbxrHe4ceDwDe1xjcuvEBCjub11GMYG

## 08 Move CTF Lets Move
- [] proof :
- [] flag hash :
- [x] proof : SnyLUIXawx
- [x] flag hash : FT2f1fkHGHz7Wj9Hq6KvSZXpbRJkK5QiBLdNyLsMCJKY

0 comments on commit cf9b2f0

Please sign in to comment.