// Copyright (C) 2012 by Nick Craig-Wood http://www.craig-wood.com/nick/
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
packagemainimport("bufio""crypto/aes""crypto/cipher""crypto/rand""encoding/base64""errors""fmt""log""os")// crypt internals
var(cryptKey=[]byte{0x9c,0x93,0x5b,0x48,0x73,0x0a,0x55,0x4d,0x6b,0xfd,0x7c,0x63,0xc8,0x86,0xa9,0x2b,0xd3,0x90,0x19,0x8e,0xb8,0x12,0x8a,0xfb,0xf4,0xde,0x16,0x2b,0x8b,0x95,0xf6,0x38,}cryptBlockcipher.BlockcryptRand=rand.Reader)// crypt transforms in to out using iv under AES-CTR.
//
// in and out may be the same buffer.
//
// Note encryption and decryption are the same operation
funccrypt(out,in,iv[]byte)error{ifcryptBlock==nil{varerrerrorcryptBlock,err=aes.NewCipher(cryptKey)iferr!=nil{returnerr}}stream:=cipher.NewCTR(cryptBlock,iv)stream.XORKeyStream(out,in)returnnil}// Reveal an obscured value
funcReveal(xstring)(string,error){ciphertext,err:=base64.RawURLEncoding.DecodeString(x)iferr!=nil{return"",fmt.Errorf("base64 decode failed when revealing password - is it obscured?: %w",err)}iflen(ciphertext)<aes.BlockSize{return"",errors.New("input too short when revealing password - is it obscured?")}buf:=ciphertext[aes.BlockSize:]iv:=ciphertext[:aes.BlockSize]iferr:=crypt(buf,buf,iv);err!=nil{return"",fmt.Errorf("decrypt failed when revealing password - is it obscured?: %w",err)}returnstring(buf),nil}// MustReveal reveals an obscured value, exiting with a fatal error if it failed
funcMustReveal(xstring)string{out,err:=Reveal(x)iferr!=nil{log.Fatalf("Reveal failed: %v",err)}returnout}funcmain(){fi,_:=os.Stdin.Stat()varobfuscatedstringifos.Args[1]=="-"&&(fi.Mode()&os.ModeCharDevice)==0{scanner:=bufio.NewScanner(os.Stdin)ifscanner.Scan(){obfuscated=scanner.Text()}iferr:=scanner.Err();err!=nil{log.Fatal(err)}}else{obfuscated=os.Args[1]}// Reveal the password
revealed:=MustReveal(obfuscated)fmt.Println(revealed)}
后记
原来有 rclone reveal,我怎么比赛的时候没看见。
help 里根本没提到,看起来像是故意隐藏的功能。
HeiLang
把题目中的 python 代码改成正确的语义。
代码
python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#!/usr/bin/env python3# SPDX-License-Identifier: CC-BY-NC-SA-4.0fromhashlibimportsha256a=[0]*10000s='''
# Omit the code .....
'''forlineins.strip().split('\n'):items=line[line.find('['):line.find(']')]num=int(line[line.find('=')+1:].strip())foriteminitems.split('|'):a[int(item.strip())]=num
#!/usr/bin/python3# SPDX-License-Identifier: CC-BY-NC-SA-4.0# The size of the file may reduce after XZRJificationfrombase64importurlsafe_b64encodefromhashlibimportsha384fromhmacimportdigestfromsysimportargvdefcheck_equals(left,right):# check whether left == right or notifleft!=right:raiseException(f'check_euqals fail {left} != {right}')defsign(file:str):withopen(file,'rb')asf:# import secretsecret=b'usssttttttce.edddddu.ccccccnnnnnnnnnnnn'check_equals(len(secret),39)# check secret hashsecret_sha384='eccc18f9dbbc4aba825c7d4f9cccce726db1cb0d0babffe47f'+ \
'a170fe33d53bc62074271866a4e4d1325dc27f644fddad'check_equals(sha384(secret).hexdigest(),secret_sha384)# generate the signaturereturndigest(secret,f.read(),sha384)if__name__=='__main__':try:# check some obvious thingscheck_equals('create','cre'+'ate')check_equals('referrer','refer'+'rer')# generate the signaturecheck_equals(len(argv),2)sign_b64=urlsafe_b64encode(sign(argv[1]))print('HS384 sign:',sign_b64.decode('utf-8'))except(SystemExit,Exception)ase:print(e)print('Usag'+'e: HS384.py <fil'+'e>')
# SPDX-License-Identifier: CC-BY-NC-SA-4.0defexgcd(a,b):ifa==0:return(b,0,1)g,y,x=exgcd(b%a,a)return(g,x-(b//a)*y,y)defmodinv(a,m):g,x,y=exgcd(a,m)ifg!=1:raiseException('modular inverse does not exist')else:returnx%mdefsolve(c,e):d=modinv(e,c.order())n=c**dreturnn
# SPDX-License-Identifier: CC-BY-NC-SA-4.0defexcrt(r,m):mo,re=m[0],r[0]n=len(r)foriinrange(1,n):(d,x,y)=exgcd(mo,m[i])if((r[i]-re)%d)!=0:raiseException("solution does not exist")x=(r[i]-re)//d*x%(m[i]//d)re+=x*momo=(mo//d)*m[i]re=re%more=(re+mo)%moreturnre,modefsolve(g,y):r,m=[],[]foriteming.standard_tuple:iflen(item)==1:continueidx=item[0]-1distance=item.index(y.permutation_list[idx])r.append(distance)m.append(len(item))ans,_=excrt(r,m)returnans
LD_PRELOAD
...
In secure-execution mode, preload pathnames containing
slashes are ignored. Furthermore, shared objects are
preloaded only from the standard search directories and
only if they have set-user-ID mode bit enabled (which is
not typical).
...
There are various methods of specifying libraries to be
preloaded, and these are handled in the following order:
(1) The LD_PRELOAD environment variable.
(2) The --preload command-line option when invoking the
dynamic linker directly.
(3) The /etc/ld.so.preload file (described below).
# SPDX-License-Identifier: CC-BY-NC-SA-4.0fromqiskitimportQuantumCircuit,assemble,transpile,IBMQfromQconfigimportAPItokenqc=QuantumCircuit(129,128)foriinrange(128):qc.h(i)qc.x(128);qc.h(128);qc.barrier()# Omit the code for drawing ......qc.barrier()foriinrange(128):qc.h(i)qc.measure(i,i)IBMQ.enable_account(APItoken)backend=IBMQ.ibmq.providers()[0].get_backend('ibmq_qasm_simulator')qobj=assemble(transpile(qc,backend=backend),shots=8096)job=backend.run(qobj)result=job.result()count=result.get_counts()print(count)# {'0110011001101100011000010110011101111011....01111101': 8096}# 0x66 #0x6c 0x61 0x67 0x7b 0x7d# f l a g { }