0%

簡介

Ronald Fisher 和 Frank Yates 發明的均勻洗牌算法

算法

索引從0開始往len(卡排列表)遞增,索引i與隨機選擇的卡牌交換 隨機選擇的卡牌如果用rand() mod (len(卡排列表) - i)取隨機的卡牌,會不均勻

CPE (沒)解題技巧

我遇到的困難

scanf

測資 1234 A

1
scanf("%d%c",&i,&c);

看起來可以 i=1234 c=’ '

1
scanf("%d %c",&i,&c);

空白佔一格

沒有debuger

先問問同學你們用的debuger是什麼? 只有 printf() 所以我多用 #ifdef debug

英文

我多先讀一遍,把全部不會跟不確定意思的字抄下來查,然後再讀一遍 他不能複製貼上

簡介

一個簡單的 RSA 實作

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import random
#des p,q
p=113
q=117

prim=[64513,64553,64577,65419,66301,65651,67139,67141,65537,66293,65687,66919,66347,65447]

def gcd(p,q):
  if (q == 0):
    return ( p, 1, 0 )
  d,b,a = gcd(q, p % q);
  b=b-(p//q)*a
  return (d, a, b)
  

def inverse(k,n):
    d,a,b= gcd(k, n);
    if (d > 1):
      print("Inverse does not exist."); return 0;
    if (a > 0): 
      return a;
    return n + a;

def keygen(p,q): 
  n=p*q
  oln=(q-1)*(p-1)
  e=prim[random.randint(0,len(prim))]
  d=inverse(e,oln)
  return (e,n),(d,n)

def decode(s):
  #english only
  ls=[]
  if len(s)%2==1:
    s+=' '
  for i in range(0,len(s),2):
    ls.append(ord(s[i])*0xff+ord(s[i+1]))
  return ls

def encode(ls):
  s=""
  for i in ls:
    s=s+chr(i//0xff)+chr(i%0xff)
  return s

def syc(m,e,n):
  c=[]
  for i in range(0,len(m)):
    c.append(pow(m[i],e,n))
    
  return c

def usyc(c,d,n):
  m=[]
  for i in range(0,len(c)):
    m.append(pow(c[i],d,n))
    
  return m

print(keygen(p,q))

c=syc(decode("nttucsie"),7237327049, 26217266885746803617)
m=usyc(c,4962162255038558585, 26217266885746803617)
print(encode(m))

keygen() 用以產生金鑰對,返回temp(公,私),pq因大於10^10 sys() 給定encod過的串列及私鑰,返回加密串列,建議以base64 服用 usys() 給定加密串列及公鑰,返回encod過的串列。

target

我相信你們大家多看過 chrome://dino/ 就復刻一個,應該會在uart上,但RJ-433的2.5mb/s讓人恐懼 如果寫不上去就去LCD(應該是兩個點),計分會用七段顯示器。 蹲下可以,腳不會動。

目的

我致敬了google的小恐龍

先示範

lcd版

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#include <stdlib.h>
#include "WT59F064.h"
#include "lcd.h"
#include "keyboard_io.h"

int cactus[2]={0xffff,0xffff},djmp=0,score=0,gameover=0;

char trans(int i){
	if(i<10){
		return '0'+i;
	}else{
		return 'A'+(i-10);
	}
}

void ISR_forward(){
	TIM0_CNT = 0;
	TIM0_OFIF |= BIT4;
	if(gameover==1){
		return;
	}
	if(TIM0_MAT0A>100){
		TIM0_MAT0A-=1;
	}
	WriteIns(0x0100);
	if(cactus[0]==0){
		cactus[0]=0xffff;
	}else if(cactus[0]<=0x0f00){
		cactus[0]-=0x0100;
	}
	if(cactus[1]==0){
		cactus[1]=0xffff;
	}else if(cactus[1]<=0x0f00){
		cactus[1]-=0x0100;
	}

	if(djmp>0){
		WriteIns(0x8300);
		WriteData('D');
		--djmp;
	}else{
		WriteIns(0xc300);
		WriteData('D');
	}

	if(cactus[0]<0x0f00){
		WriteIns(0xc000+cactus[0]);
		WriteData('C');
	}
	if(cactus[1]<0x0f00){
		WriteIns(0xc000+cactus[1]);
		WriteData('C');
	}

	WriteIns(0x8c00);
	WriteData(trans(((score&0xf000)>>12)));
	WriteData(trans(((score&0x0f00)>>8)));
	WriteData(trans(((score&0x00f0)>>4)));
	WriteData(trans((score&0x000f)));
	++score;
	return;
}

void Timer0_Initial(void)
{
	TIM0_CTL |= BITF;  // Timer Enable
	TIM0_CNT = 0; //incremented every (pscl + 1) of trigger source
	TIM0_PSCL = 23999; //°£ÀW­È
	TIM0_MAT0A = 1000; //Match mat0a register for output match mode
	TIM0_IE |= BIT4; // Interrupt enable for mat0a
	IE0_0 |= BIT3;  // 1: Enable Timer 0 interrupt
	TIM0_CTL |= BIT0; // Timer Start
	return;
}

void Timer1_Initial(void)
{
	TIM1_CTL |= BITF; // Timer Enable
	TIM1_CNT = 0; //incremented every (pscl + 1) of trigger source
	TIM1_PSCL = 23999; //°£ÀW­È
	TIM1_CTL |= BIT0;
	return;
}


void IntInitial(void)
{
	initIntr();
	GIE_ENABLE();
	return;
}

void PWM_Initial(void)
{
	GPIO_ACT_PD = 0xFFFB;//GPIO port D.2 enables the PWM function.
	PWM4_PWM7_BASE_CLK = 0x3; 	// MUC Clock = 24MHz  => 2MHz
	PWM4_PWM7_ENABLE = 0x40; 	//PWM6 enable
	return;
}

void quiet_PWM6(){
	PWM6_CLOCK=10;
	PWM6_PERIOD=0;
	PWM6_DUTY=0;
	return;
}

int main(){
	System_Control_00 = ( System_Control_00 | 0x000E);
	// High speed external Xtal clk selection(011:24MHz); 1: HSE oscillator on
	System_Control_04 = ( System_Control_04 | 0x0001);
	// 1: Select HSE as system clock source
	InitialLCD();			// LCD initial
	IntInitial(); 			// MCU interrupt initial
	PWM_Initial();
	Timer0_Initial();
	Timer1_Initial();

	quiet_PWM6();
	while(1){
		KeyScan();
		if(GetKeyScanV()==0xE7 && djmp<=0 ){
			djmp=3;
			PWM6_CLOCK=10;
			PWM6_PERIOD=346;
			PWM6_DUTY=173;
			delay1(65534);
			quiet_PWM6();


		}else if(GetKeyScanV()==0xEB){
			gameover=1;
			while(1){
				if(GetKeyScanV()== 0xED){
					gameover=0;
					break;
				}
				KeyScan();
			}
		}

		if(djmp<=0){
			if(cactus[0]==0x0300 || cactus[1]==0x0300){
				WriteIns(0x8300);
				WriteString("game over");
				gameover=1;
				while(1){;}
			}
		}
		if(cactus[0]>0x1000){
			if((TIM1_CNT%51)<3){
				cactus[0]=0x0f00;
			}
		}
		if(cactus[1]>0x1000 && cactus[0]!=0x0f00){
			if((TIM1_CNT%51)<17){
				cactus[1]=0x0f00;
			}
		}
		if(TIM1_CNT>0xefff){
			TIM1_CNT=0;
		}
	}
	return 0;
}

使用零件

LCD,中斷

型別

就是我們對一串資料的態度 先看一串資料 請幻想有一堆格子,每隔多只有0跟1兩種可能,存取方式不限

整數

1
unsigned int i;

連續16 or 32 or 64 bit 0x0000 -> 0 0x0001 -> 1 0xffff -> 65535

1
int i;

我想用最左的bit當正負記號1為負 然後就出現兩個0了0x8000 0x0000 所以把0xffff 當-1 0xfffe -> -2 正負轉換為 (~i)+1

c的變數可見域

半夜隔壁房再吵,睡不著寫第一篇教學幹話。其實是自己金魚腦,要筆記。

區域變數

區域變數(幹在函數第一層),你寫在函數裡的那一種(main也算),只有宣告下面的看的見,如果再”{}”裡,就裡面看的到。

簡介

大學時程式語言課程的上課筆記

記憶體管理議題

ada

動態的他會收回去

c/c++

自己管,指標可以指向任何地方(通常拿來做記憶體管理) 指標可移動 須明確取參 參照像const pointer

c#

僅參照

基本概念

動態請求的array 就是太小重要更大的,然後搬過去 看code

1
2
3
4
5
6
7
8
9
tem* resize(unsigned long vsize){
        tem *pay=new tem[vsize],*ppa,*endp=pay+vsize,*par;
        for(par=arr,ppa=pay;ppa<=endp&&par<=endc;++ppa,++par){
            *ppa=*par;
        }
        delete [] arr;
        arr=pay;crr=par;endc=endp;
        return arr;
    }

他有規範要寫的函式

BeforeRun

ConfigStruct(VaultPath=PosixPath(’/opt/note’), ExportPath=PosixPath(’/home/eric/Downloads/ericblog/content/post’), MdTo=<EnumMdTo.HugoBundle: ‘hugobundle’>, MdName=<EnumMdName.Uuidv4: ‘uuid’>, UrlPrefix=’.’, ResourceTo=<EnumResourceTo.Root: ‘root’>, UrlRewrite=<EnumUrlRewrite.RelativeMd: ‘relativemd’>, ResourceName=<EnumResourceName.Uuidv4: ‘uuid’>, ResourceAnoint=PosixPath(’.’), SlugPropertie=<EnumSlugPropertie.Uuidv4: ‘uuid’>, DateFormat=’%Y-%m-%d’, ReportDetail=True) VaultPath : /opt/note ExportPath : /home/eric/Downloads/ericblog/content/post

Test /opt/note/DataView.md

Fail PropertieParsar — Not at first of file {}

Test /opt/note/ExcludeFile.txt

Fail PropertieParsar Not suffix with .md {}

Test /opt/note/obsibian.md

Fail PropertieParsar — Not at first of file {}

Test /opt/note/sync.bash

Fail PropertieParsar Not suffix with .md {}

Test /opt/note/sync.md

Fail PropertieParsar — Not at first of file {}

Windows 無法在未使用uac提權的前提下建立軟連結(即使有資料夾完全控制權限也不行),但可以以以下方式繞過:

  • 開啟開發者模式
  • mklink 應該也可以繞過(待確認)