leah@leah-pc ~> python3
Python 3.8.10 (default, Nov 26 2021, 20:14:08)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> imgsrc = b'\xd9\x01\x10\x02TZH\x00(\x00\xa2\x8b\x80Q@\x05\x14\x00QJ\xe0\x14P\x01E0\n(\x00\xa2\x80\n(\x00\xa2\x90\x05\x14\xc0(\xa0\x02\x8aL\x02\x8a\x00(\xa6\x01E\x00\x19\xa2\x90\x05\x14\x00QL\x02\x8aL\x02\x8aw\x00\xa2\x80?\xff\xff\xff\xff\xd9\x00\x0bV\x00\x00'
>>> file = open('myimage','wb')
>>> file.write(imgsrc)
80
>>>
leah@leah-pc ~> file myimage
myimage: data
leah@leah-pc ~> hexdump myimage
0000000 01d9 0210 5a54 0048 0028 8ba2 5180 0540
0000010 0014 4a51 14e0 0150 3045 280a a200 0a80
0000020 0028 90a2 1405 28c0 02a0 4c8a 8a02 2800
0000030 01a6 0045 a219 0590 0014 4c51 8a02 024c
0000040 778a a200 3f80 ffff ffff 00d9 560b 0000
0000050
import hashlib, uuid
salt = uuid.uuid4().hex
hashed_password = hashlib.sha512(password + salt).hexdigest()
#!/usr/bin/python3
import hashlib, uuid
SEPARATOR = "&"
# generate hash string with salt
def gen_hash(pwd, salt):
return hashlib.sha512(pwd + salt).hexdigest()
# generage hash password string (for safe to file)
def gen_pw_string(pwd):
salt = uuid.uuid4().hex
return salt + SEPARATOR + gen_hash(pwd, salt)
# parse hash password string, split it by salt and password hash
def parse_pw_string(pwstring):
return pwstring.split(SEPARATOR)
# check password by its password hash string
def check_pwd(pwd, pwstring):
salt, _pwhash = parse_pw_string(pwstring)
pwhash = gen_hash(pwd, salt)
return pwhash == _pwhash
### test time!
pwd1 = "123456"
pwd2 = "qwerty"
# genetate hash strings (may be saved to file or DB)
pwstring1 = gen_pw_string(pwd1)
pwstring2 = gen_pw_string(pwd2)
print(pwd1, pwstring1)
print(pwd2, pwstring2)
# check passwords
# must be True
print(check_pwd(pwd1, pwstring1))
print(check_pwd(pwd2, pwstring2))
# must be False
print(check_pwd(pwd1, pwstring2))
print(check_pwd(pwd2, pwstring1))
('123456', 'f2b56ad9006a475e8c4f9b64446c3f5b&46c2d252a2667cc4b5a754ef5816e981570fd4bd9ced3ed1a6f6aaeae8ae83b795d6ffb66b3fe34650469b1c0d537785c2611157d41ebee6e54dc09527600a0c')
('qwerty', 'f2b56ad9006a475e8c4f9b64446c3f5b&3da9c4223c9fa2c66f5d70432401db14a89ddfe6feb99423083d152f98ef199d484b95b09a6535c766f28223c422cd1d862250867c12c7077144564b5c3fbc79')
True
True
False
False
long startTime = System.nanoTime();
methodToTime();
long endTime = System.nanoTime();
long duration = (endTime - startTime);
Instant start = Instant.now();
Thread.sleep(63553);
Instant end = Instant.now();
System.out.println(Duration.between(start, end)); // prints PT1M3.553S
truncate -s 500M my-file-system.img
- создать файликmkfs.ext4 my-file-system.img
- создать файловую систему на немmount -o loop my-file-system.img /mnt
- подмонтироватьdf -h /mnt
- проверить размерчикumount /mnt
- отмонтироватьroot@leah-pc /h/leah# truncate -s 500M my-file-system.img
root@leah-pc /h/leah# mkfs.ext4 my-file-system.img
mke2fs 1.45.5 (07-Jan-2020)
Discarding device blocks: done
Creating filesystem with 128000 4k blocks and 128000 inodes
Filesystem UUID: ada9f825-92d5-4410-b186-eda1ef2edfeb
Superblock backups stored on blocks:
32768, 98304
Allocating group tables: done
Сохранение таблицы inod'ов: done
Создание журнала (4096 блоков): готово
Writing superblocks and filesystem accounting information: готово
root@leah-pc /h/leah# mount -o loop /home/leah/my-file-system.img /mnt
root@leah-pc /h/leah# df -h /mnt
Файл.система Размер Использовано Дост Использовано% Cмонтировано в
/dev/loop26 469M 768K 433M 1% /mnt
root@leah-pc /h/leah# umount /mnt