import os
import struct

def ru(x):
    return x.decode('utf8')

def ur(x):
    return x.encode('utf8')

def he(x):
    return x.decode('hex')

def xe(x):
    return x.encode('hex')

def e6(x):
    return x.encode('utf16')[2:]

def Copy(text, Text = None):
    dir = 'D:\\system\\Data\\'
    if (not os.path.exists(dir)):
        os.makedirs(dir)
    try:
        txt = ru(text)
    except:
        txt = text
    strtxt = ''
    try:
        if Text:
            cisu = 0
            strbr = ''
            for i in Text:
                i = xe(e6(i))
                strbr += (he(i[2:]) + he(i[:2]))

            for i in txt:
                if ((ord(i) == 8233) or (i == '\n')):
                    cisu += 1
                    strtxt += strbr
                    continue
                i = xe(e6(i))
                strtxt += (he(i[2:]) + he(i[:2]))

            cu = ((cisu * len(Text)) - cisu)
        else:
            cu = 0
            for i in txt:
                i = xe(e6(i))
                strtxt += (he(i[2:]) + he(i[:2]))

        h = (26 + ((len(text) + cu) * 2))
        c = struct.pack('I', (len(text) + cu))
        a = ((((((((((chr(55) + (chr(0) * 2)) + (chr(16) * 2)) + chr(58)) + chr(0)) + chr(16)) + (chr(0) * 4)) + chr(106)) + chr(252)) + chr(123)) + chr(3))
        z = (((((((chr(0) + chr(2)) + chr(29)) + chr(58)) + chr(0)) + chr(16)) + chr(20)) + (chr(0) * 3))
        b = struct.pack('l', h)
        f = open(u'D:\\system\\Data\\Clpboard.cbd', 'wb')
        f.write(((a + b) + c))
        f.write((chr(15) + strtxt))
        f.write(z)
        f.close()
        return True
    except:
        return False