우연히 검색해서 찾아낸 툴 : Curvesnap
논문에 숫자가 아닌 그래프로 데이터가 나와 있는 경우,
그것을 숫자 테이블로 바꾸어 주는 프로그램이다.
어느 정도의 에러를 감안할때 꽤 그럴 듯한 값을 끄집어 낼 수 있다.
사용법도 나름 편리. 자세한 것은 링크를 참조....(귀찮은가)
나중에 좀 자세히 쓰자.
http://xoofee.com/2012/12/curvesnap/
2014년 5월 22일 목요일
2014년 5월 19일 월요일
Linux tips
1. VI, VIM tips
prepending the "\c" string. Using "\C" will make the pattern to match case.
(1) search strings with special character : put \ in front of any special character
(2) wild character : use .* instead *
Ex: sed ‘s/\[.*\]/xxx/’ replaces string ‘[......]’ to ‘xxx’
1. To remove the ^M character, in ViM, write the following in the command mode and press :w to save the changes:
:set fileformat=unix
2. Or, type this script in ViM, in the command mode and type :w to save the changes:
^V^M gives ^M character in the screen
:1,$s/^V^M//g
3. With sed:
$ sed 's/^M//g' filename > newfilename
4. With Dos2Unix:
$ dos2unix filename newfilename
5. With col:
$ cat filename | col -b > newfilename
use Internet Explorer (IE) as an FTP client.
ftp://[id]@[ftpaddress]:{port} or ftp://[ftpaddress]:{port}
rename "s/ *//g" *.mp3
Notepad++, Visual Studio, and some others: Alt + drag.
vim: Ctrl + v
Netbeans 7.1 can select columns (Rectangular Selection) with Ctrl + shift + R
Since Eclipse 3.5, you just need to type Alt+Shift+A
In Kate toggle Ctrl + shift + B
[wild cards][Control+shift+x, *] (즉 ^X*)
shows all visible files match. Then remove those from the list to keep.
2. Set encrption password by ':X'
3. make change and save file. Now the file is encrypted.
4. To remove ecncryption, set blank key by 'set key=' .
(1)Case Insensitive search in vi
If you want to ignore case for one specific pattern, you can do this byprepending the "\c" string. Using "\C" will make the pattern to match case.
(2) Change characters into all lower or upper capitals.
":%s/[A-Z]/\L&/g" or ":%s/[a-z]/\U&/g"(3)Copy/Paste to/from clipboard.
: Check 'vim --version' if it has '+clipboard' . If it is not, one may install vim-gnome or vim+gtk.
One can copy to clipboard after selecting in visual mode by "+y
(With shift key, press " and press + , then release shift key and press y ).
2. SED tips
(1) search strings with special character : put \ in front of any special character
(2) wild character : use .* instead *
Ex: sed ‘s/\[.*\]/xxx/’ replaces string ‘[......]’ to ‘xxx’
Removing ^M from file:
1. To remove the ^M character, in ViM, write the following in the command mode and press :w to save the changes:
:set fileformat=unix
2. Or, type this script in ViM, in the command mode and type :w to save the changes:
^V^M gives ^M character in the screen
:1,$s/^V^M//g
3. With sed:
$ sed 's/^M//g' filename > newfilename
4. With Dos2Unix:
$ dos2unix filename newfilename
5. With col:
$ cat filename | col -b > newfilename
use Internet Explorer (IE) as an FTP client.
ftp://[id]@[ftpaddress]:{port} or ftp://[ftpaddress]:{port}
change multiple file names
rename "s/ *//g" *.mp3
column editing:
Notepad++, Visual Studio, and some others: Alt + drag.
vim: Ctrl + v
Netbeans 7.1 can select columns (Rectangular Selection) with Ctrl + shift + R
Since Eclipse 3.5, you just need to type Alt+Shift+A
In Kate toggle Ctrl + shift + B
Delete many files except several:
[wild cards][Control+shift+x, *] (즉 ^X*)
shows all visible files match. Then remove those from the list to keep.
VIM editor encryption:
1. edit .vimrc file and add 'set cm=blowfish'. This gives better encryption.2. Set encrption password by ':X'
3. make change and save file. Now the file is encrypted.
4. To remove ecncryption, set blank key by 'set key=' .
Python tips
1. change list of strings to list of arrays
(1) use map(command, list) : apply ‘command’ to all elements of ‘list’
-> in python 2: map returns list
-> in python 3: map returns iterator
(2) use list comprehension: [ ‘cmd’(x) for x in ‘list’]
2. search strings in lists
(1) return index of matching list elements
matching= [lines.index(s) for s in lines if "searching" in s]
3. join two arrays as columns
np.column_stack(array1,array2)
4. multiple arguments as a tuple or unpack tuple
*(tuple) unpacks the tuple
**(dictionary) unpacks the dictionary
it enables
(1) defined function to receive arbitary number of arguments
def f(*arguments)
(2) passing arguments as tuple
x=(1,2,3)
f(*x) is equivalent f(1,2,3)
Fortran : string 관련 tips
1. Change between numbers and characters(string)
(1) Use CHAR(48+num) trick: However this works only for 1 digit number
(2) Use internal file method :
* To convert number into strings, write
* To convert number into strings, write
WRITE(string_name,format) number
(be careful that we need to use I3.3 instead of I3 to
put zeroes on the left of number )
* To convert strings into number, read
READ(string_name,format) number
(3) If we need only part of string, use slicing
string(begin:end)
*In case of one character, string(num) does not work.
Have to use
string(num:num)
예를 들어서 길이가 달라지는 변수에 대해 format string을 쓰고 싶은 경우.
길이가 n 인 실수 array v(1:n) 를 출력한다고 하자.
WRITE(fmt_str,'(a,i2.2,a)') '(1x,' , n , '(f15.7,1x))'
( n=3인 경우) fmt_str 은 '(1x,03(f15.7,1x))' 가 되고
WRITE(* , trim(fmt_str)) v
로 v 를 출력할 수 있다.
2. Deal with system commands in Fortran
(1) get_command_argument(i,arg): get command arguments
return i-th command argument as string
0-th argument is command itself
(2) SYSTEM( strings ) : use system command
(3) TRIM : Removes trailing blank characters of a string
(4) call getcwd(path): get current working directory
call chdir(path) :change current working directory
포트란의 기본 인풋/아웃풋 들, 파일 핸들링은 current working directory를
기준으로 한다. call SYSTEM(‘cd path’)
does not actually change the environment for fortran
3. quotes in strings : ‘’ represent ‘ in string. thus ‘’’ x’’’ -> ‘x’
4. Fw.d : 전체 캐릭터 수가 w 이고,( 부호, . 포함), 소수점뒤로 d 캐릭터
Ew.d: 전체 캐릭터 수가 w 이고,( 부호, ., E+00 포함) 소수점 뒤로 d 캐릭터
RSA 암호
최근에 읽은 책중에 <침팬지도 이해하는 5분 수학>(? 제목이 정확하진 않지만 비슷할 것같다.)이 있다. 여러가지 수학에 관한 짧은 칼럼들을 모아놓은 것인데 그 중에 RSA 암호 체계에 관한 글이 있었다. 간단히 설명하면, 현재의 대분의 공개키 암호체계의 기본이 되는 것으로 페르마의 소정리를 이용하는 것이다.
일단, 페르마의 소정리란
(1) n 이 소수이고, 1<k<n-1 인 k 에 대해,
k^{n-1} mod n =1
이다.
( 비슷하게 k^n mod n =k )
예를 들어 n=7, k=5 라면, 5^{7-1} mod 7 = 1
(2) 한 단계 더 일반화 시키면,
임의의 정수 n 에 대해, 1<k<n 이고 n 과 서로소인 k 가 있을 때,
n 보다 작으면서 1 또는 n과 서로소인 수의 개수를 phi(n) 이라고 하면,
k^(phi(n)) mod n =1
이다.
n 이 소수이면 phi(n)=n-1 이 되어 (1) 과 같아진다.
예를 들어 n=10, k=7 , phi(10)=4 (즉, 9,7,3,1) 이고
7^4 mod 10 = 1
이제 RSA 암호를 보자. 이 경우 등장하는 수는 p, q, L, n, k 인데, 각각은
p, q : 서로다른 큰 소수
n : p, q의 곱 n=p * q
k , L : 다음 관계를 만족하는 두 수
(k*L) mod phi(n)=1
여기서, phi(n)=(p-1)*(q-1) 이다.
이 중 p, q , L은 비밀로 하고 n과 k는 공개한다.
(1) 암호화 : 먼저 메세지를 숫자 m 이라고 하자. 그러면, 암호문은
r= m^k mod n
으로 구해진다. 즉, 이 경우 알려진 n과 k를 이용하므로
누구나 암호화할 수 있다.
(2) 해독 : 받은 암호문으로 부터
r^L mod n =m
을 계산하여 메세지 m 을 얻는다.
이 과정이 페르마의 소정리를 이용한 것이다.
r^L mod n = (m^k)^L mod n = m^(k*L) mod n
= m^( s*phi(n)+1 ) mod n
= m* (m^phi(n))^s mod n
= m mod n = m
따라서, 해독은 L 을 알아야만 할 수 있다. ( p, q 자체는 몰라도 됨.)
만약 누군가가 알려진 n 과 k 로부터 L을 계산할 수 있다면,
암호가 풀리게 된다.
쉬울까?
예를 들어 n=2773, k=17 이 알려져 있다고 하자. 이 경우 해야 할 일은
먼저 2773과 서로소인 수의 개수 phi(2773) 을 구하고 (이 부분이 어렵다),
17*L mod phi(2773) =1 이 되는 수 L을 구하는 것이다.
문제는 이미 p=47, q=59를 알고 있는 경우에는 phi(2773)=2668 임을 알 수 있지만,
p와 q를 모를 경우 phi(2773)을 구하기는
쉽지 않다는 것이다. 특히 만약 n 이 수백자리수가 되면 더욱 어려울 것이다.
피드 구독하기:
글 (Atom)