# Scprits

{% code overflow="wrap" %}

```python
>>> import string #thư viện

>>> string.ascii_letters
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'

>>> string.ascii_lowercase
'abcdefghijklmnopqrstuvwxyz'

>>> string.ascii_uppercase
'ABCDEFGHIJKLMNOPQRSTUVWXYZ'

>>> string.digits
'0123456789'

>>> string.hexdigits
'0123456789abcdefABCDEF'

>>> string.octdigits
'01234567'

>>> string.punctuation
'!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~'

>>> string.whitespace
' \t\n\r\x0b\x0c'

>>> string.printable   #bao gồm tất cả các loại trên
'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~ \t\n\r\x0b\x0c'
```

{% endcode %}

```python
# chuyển từ các số string thành int
>>> grades = ["82", "84", "71", "64", "66"]
>>> new_grades = [int(g) for g in grades] # nếu string là hex thì int(g, 16)...
>>> print(new_grades)
[82, 84, 71, 64, 66]

```

{% code overflow="wrap" %}

```python
>>> import base64
>>> from binascii import unhexlify
>>> hex = unhexlify('72bca9b68fc16ac7beeb8f849dca1d8a783e8acf9679bf9269f7bf')
>>> hex
b'r\xbc\xa9\xb6\x8f\xc1j\xc7\xbe\xeb\x8f\x84\x9d\xca\x1d\x8ax>\x8a\xcf\x96y\xbf\x92i\xf7\xbf'
>>> flag = base64.b64encode(hex)
>>> flag
b'crypto/Base+64+Encoding+is+Web+Safe/'
```

{% endcode %}

{% code overflow="wrap" lineNumbers="true" %}

```python
# zip() trả về đối tượng zip được ghép nối 2 biến với nhau
for b1, b2 in zip(input, key):
        output += bytes([b1 ^ b2])
```

{% endcode %}

{% code overflow="wrap" %}

```python
# to reverse the string
>>> str = "anh"
>>> str[::-1]
'hna'

# kí tự cuối cùng
>>> str[-1]
'h'

# list to string
>>> lst = ("f", "l", "a", "g")
>>> x = "".join(lst)
>>> print(x)
flag

```

{% endcode %}

{% code overflow="wrap" %}

```python
# để xóa màn hình shell trong python
>>> import os
>>> os.system('cls')
```

{% endcode %}

{% code overflow="wrap" %}

```python
# bytes to string
>>> b = b"Lets grab a \xf0\x9f\x8d\x95!"
>>> type(b)
<class 'bytes'>
>>> s = b.decode('utf-8')
>>> s
'Lets grab a 🍕!'
```

{% endcode %}

## Input data

```python
strings = str(input("Input strings: "))
num = int(input("Input num integer: "))
num_float = float(input("Input num float: "))
print(num,strings,num_float)
```

## Create File

```python
with open('name_file.txt', 'w') as f:
    f.write('test')

lines = ['1','2','3']
with open('name_file1.txt', 'w') as f:
    for line in lines:
        f.write(line)
        f.write('\n')

more_lines = ['add', 'the end']
with open('name_file2.txt','a') as f:
    f.write('\n'.join(more_lines))
    
f = open('name_file3.txt' , 'r')
print(f.read())
```

## Class

```python
class animal:
    atributo1 = "a1"
    atributo2 = "a2"
    
    def funcao(self)"
        print(self.atributo1)
        print(self.atributo2)
nomeanimal = animal()
print(nomeanimal.atributo2)
```

## Exception

```python
a = 12
b = 0
try: y = a/b
print(y)
except ZeroDivisionError:
    print('...')
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://viettaliii.gitbook.io/home/ctf/cheatsheet/python/scprits.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
