<commit_before>from subprocess32 import Popen,call,PIPE
import os

def createCrypto(fuuid,password,user="daniel",fsize="125M",filedirectory=os.getcwd(),mountdirectory=os.getcwd()):
    cryptfile = os.path.join(filedirectory,fuuid+".luks")
    mountdir = os.path.join(mountdirectory,fuuid)
    
    #Create the file and make mount directory
    code = call(["fallocate","-l",fsize,cryptfile])
    os.mkdir(mountdir)
    
    #Set up the file
    csetup = Popen(["cryptsetup","-y","luksFormat",cryptfile],
                stdin=PIPE)
    csetup.communicate("YES\n"+password+"\n")
    csetup.wait()
    
    #Open the volume
    csetup = Popen(["cryptsetup","-y","luksOpen",cryptfile,fuuid],
                stdin=PIPE)
    csetup.communicate("YES\n"+password+"\n")
    csetup.wait()
    
    print code
def unmountCrypto(fuuid,mountdirectory=os.getcwd()):
    mountdir = os.path.join(mountdirectory,fuuid)
    
    
createCrypto("r24rwer23r","testingtesting123",fsize="64M")
raw_input("ok")
unmountCrypto("r24rwer23r")<commit_msg>Working crypto using cryptsetup<commit_after>from subprocess32 import Popen,call,PIPE
import time
import os

def createCrypto(fuuid,password,user="daniel",fsize=64,filedirectory=os.getcwd(),mountdirectory=os.getcwd(),randomInit=False):
    cryptfile = os.path.join(filedirectory,fuuid+".luks")
    mountdir = os.path.join(mountdirectory,fuuid)
    maploc = os.path.join("/dev/mapper",fuuid)
    
    #Create the file
    if (randomInit==False):
        #Simply allocate a file
        code = call(["fallocate","-l",str(fsize)+"M",cryptfile])
    else:
        #Create the file filling it with 0s
        call(["dd","if=/dev/urandom","of="+cryptfile,"bs=1M","count="+str(fsize)])
    
    #Make the mount directory
    os.mkdir(mountdir)
    
    #Set up the file
    csetup = Popen(["cryptsetup","luksFormat",cryptfile],
                stdin=PIPE)
    csetup.communicate(password+"\n")
    csetup.wait()
    
    #Open the volume
    csetup = Popen(["cryptsetup","luksOpen",cryptfile,fuuid],
                stdin=PIPE)
    csetup.communicate(password+"\n")
    csetup.wait()
    
    #Make the filesystem ext4
    code = call(["mkfs.ext4","-j",maploc])
    
    print code
    
    #Mount it!
    code = call(["mount",maploc,mountdir])
    
    print code
    
    #Set the folder permissions to the user!
    code = call(["chown",user+":"+user,mountdir])
    
    print code
    
    code = call(["chmod","700",mountdir])
    print code
    
def mountCrypto(fuuid,password,filedirectory=os.getcwd(),mountdirectory=os.getcwd()):
    cryptfile = os.path.join(filedirectory,fuuid+".luks")
    mountdir = os.path.join(mountdirectory,fuuid)
    maploc = os.path.join("/dev/mapper",fuuid)
    
    #Open the volume
    csetup = Popen(["cryptsetup","luksOpen",cryptfile,fuuid],
                stdin=PIPE)
    csetup.communicate(password+"\n")
    csetup.wait()
    
    #Mount it!
    code = call(["mount",maploc,mountdir])
def suspendCrypto(fuuid):
    print call(["cryptsetup","luksSuspend",fuuid])
def resumeCrypto(fuuid,password):
    csetup = Popen(["cryptsetup","luksResume",fuuid],
                stdin=PIPE)
    csetup.communicate(password+"\n")
    csetup.wait()
    
def unmountCrypto(fuuid,mountdirectory=os.getcwd()):
    mountdir = os.path.join(mountdirectory,fuuid)
    
    code = call(["umount",mountdir])
    print code
    
    print call(["cryptsetup","luksClose",fuuid])
#createCrypto("r24rwe23r","testingtesting123",fsize="64M")
fuuid = "testcrypt"
pwn = "testingtesting123"

t = time.time()
createCrypto(fuuid,pwn)
print "create:",time.time()-t
raw_input("ok")
t= time.time()
unmountCrypto(fuuid)
print "umount:",time.time()-t
raw_input("ok")
t = time.time()
mountCrypto(fuuid,pwn)
print "mount:",time.time()-t
raw_input("ok")
t= time.time()
suspendCrypto(fuuid)
print "suspend:",time.time()-t
raw_input("suspended")
t= time.time()
resumeCrypto(fuuid,pwn)
print "resume:",time.time()-t
raw_input("ok")
t= time.time()
unmountCrypto(fuuid)
print "umount:",time.time()-t
raw_input("done")
{'fraction_non_alphanumeric': 0.1606744359037937, 'fraction_numerical': 0.010166129432184479, 'mean_word_length': 3.9679802955665027, 'pattern_counts': {'":': 1, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2600407', 'n_tokens_mistral': 1494, 'n_tokens_neox': 1439, 'n_words': 219}