본문 바로가기

Software Engineering18

파이썬을 이용한 파일 압축/압축 풀기 프로그램 만들기 1. 개요 - 목적 : 파이썬을 이용한 파일 압축/압축 풀기 프로그램 만들기 - 난이도 : 하 - 사용 라이브러리 : zipfile, sys, os 2. 준비 - python3 - linux 환경 3. 코드 작성 1. 우선 만들고자 하는 프로그램을 정의하자면 다음과 같다. 'zip.py [디렉터리명]' 명령어를 통해 해당 디렉터리 하위 파일에 대한 압축을 수행하여 '디렉터리.zip' 을 생성하고 'unzip.py [zip파일명]' 명령어를 통해 해당 zip파일 압축을 풀어 동일 파일명의 디렉터리를 생성한다. 2. 먼저 압축 프로그램(zip.py)를 만들어보자. zipfile 라이브러리를 통해 압축파일을 write하기위해서는 대상 파일들의 모든 파일 '경로'가 필요하다. 이에 압축하고자 하는 디렉터리의 모.. 2022. 4. 24.
파이썬를 이용한 Unix password cracker 만들기 1. 개요 - 목적 : unix password cracker 만들기 (SHA512 해시 패스워드 기준) - 난이도 : 하 - 사용 라이브러리 : crypt 2. 준비 - python3 3. 코드 작성 1. python 기본 라이브러리의 해시 기능을 테스트 해보자. salt와 해시시키고자 하는 plain text를 삽입하면 다음과 같은 결과를 얻는다. import crypt string1 = 'HX' #salt string2 = 'egg' #plain text print(crypt.crypt(string2, string1)) #Hash digested ###### print ###### └─$ python3 crypt_test.py HX9LLTdc/jiDE 2. dictionary 파일로 부터 brute.. 2022. 4. 22.
파이썬 데이터조작 cheet sheet 1. String >>> name = "turtle priest" >>> print(name.upper()) #to uppercase TURTLE PRIEST >>> print(name.lower()) #to lowercase turtle priest >>> print(name.replace("turtle", "rabbit")) #replace substring rabbit priest >>> print(name.find('p')) #find index of char 7 2. Lists >>> myList = [] >>> myList.append('a') # append data to list >>> myList.append('b') >>> myList.append('c') >>> myList.appen.. 2022. 4. 20.
[리트코드] 100. Same Tree (tree) 문제 정보 Given the roots of two binary trees p and q, write a function to check if they are the same or not. Two binary trees are considered the same if they are structurally identical, and the nodes have the same value. Example 1: Input: p = [1,2,3], q = [1,2,3] Output: true Example 2: Input: p = [1,2], q = [1,null,2] Output: false 문제 풀이 두 개의 트리를 동시에 순회하면서 다른 부분이 발견될 경우 false를 리턴한다. Writeup /** * .. 2022. 1. 27.
[리트코드] 94. Binary Tree Inorder Traversal (tree, recursion) 문제 정보 Given the root of a binary tree, return the inorder traversal of its nodes' values. Example 1: Input: root = [1,null,2,3] Output: [1,3,2] Example 2: Input: root = [] Output: [] Example 3: Input: root = [1] Output: [1] 문제 풀이 tree의 순회방식을 먼저 이해해야한다. 1 2 3 의 형태일때 1. inorder traversal은 2-1-3 2. preorder traversal은 1-2-3 3. postorder traversal은 1-3-2 문제풀이는 재귀(recursive)를 이용한 방법과 스택을 이용한 방법이 있으나 .. 2022. 1. 27.
[리트코드] 62. Unique Paths (DP) 문제 정보 There is a robot on an m x n grid. The robot is initially located at the top-left corner (i.e., grid[0][0]). The robot tries to move to the bottom-right corner (i.e., grid[m - 1][n - 1]). The robot can only move either down or right at any point in time. Given the two integers m and n, return the number of possible unique paths that the robot can take to reach the bottom-right corner. The .. 2022. 1. 27.