Example #1
0
    def ptNumpyArray2String(self, inputtext):
        """Format the inputtext into format acceptable to des_block"""

        ptStr = ""
        for i in range(self.acq.blockSize):
            ptStr += hex2str(inputtext[i])
        return ptStr

if __name__ == "__main__":
    trsFile = '/Data/Documents/0007.trs'
    acq = LoadTraces.LoadTraces(trsFile, samplePoint = 39205)
    sboxNum = 1
    roundNum = 1    # Do not change this
    correctKey = "DEADBEEFCAFEBABE"
    leakage = 'HW'  # Use HW, HD or HDRound
    rk = des_block.roundkey(correctKey,roundNum)   # Correct Round Key of roundNum
    sk = des_block.subkey(rk,sboxNum)             # Correct Sbox Key of roundNum, sboxNum

    s = SNR(acq)
    #sig, noi = s.cpaTrace(sk, sboxNum, startTrace = 0, endTrace=10000, leakage = leakage)
    #samplePoint = np.argmax(np.abs(sig/noi))

    #print "Signal is %f, Noise is %f" % (sig[samplePoint], noi[samplePoint])
    #print "SNR is %f" % (sig[samplePoint]/noi[samplePoint])



    # Verify the accuracy using cross validation
    # Delete redundant samples and also randomise the order of the traces
    acq.shuffle()
Example #2
0
        xV=list(xV)
        xV.sort()

        for i in range(5):
            yV.append([])
        #xV = range( min(x1,x2), max(x1,x2))
        for x in xV:
            for i in range(5):
                yV[i].append(scipy.stats.norm(self.mean[i], self.sd[i]).pdf(x))
        for i in range(5):
            plt.plot(xV, yV[i])
        plt.show()



if __name__ == "__main__":
    correctKey = "DEADBEEFCAFEBABE"
    sboxNum = 1
    roundNum = 1    # Do not Change this. Currently fixed to 1.
    rk = des_block.roundkey(correctKey,roundNum)   # Correct Round Key of roundNum
    sk = des_block.subkey(rk,sboxNum)             # Correct Sbox Key of roundNum, sboxNum
    samplePoint = 0

    acq = LoadTraces.LoadTraces('traces/0001.trs', samplePoint = 3881, numTraces = 100000)
    t = DES_PI(acq)
    #acq.shuffle()
    t.buildTemplate(0x1f, sboxNum, samplePoint, startTrace = 0, endTrace =100000)
    print "PI is %f" % (t.pi(0x1f, sboxNum, samplePoint, startTrace = 0, endTrace = 100000))