コード例 #1
0
def LDPC_binary_encode(alice_thread,column_weight = 3,row_weight =4):
    total_string_length = len(alice_thread.bases_string)
    
    number_of_parity_check_eqns_gallager = int(total_string_length*0.6) 
#     alice_thread.parity_binary_matrix = gallager_matrix(number_of_parity_check_eqns_gallager, total_string_length, column_weight, row_weight)
    alice_thread.parity_binary_matrix = randomMatrix(total_string_length, number_of_parity_check_eqns_gallager, column_weight)
    alice_thread.binary_syndromes=encode(alice_thread.parity_binary_matrix,alice_thread.bases_string,alphabet=2)
コード例 #2
0
ファイル: System.py プロジェクト: hbofffw/full-qkd-system
def LDPC_binary_encode(alice_thread, column_weight=3, row_weight=4):
    total_string_length = len(alice_thread.bases_string)
    
    number_of_parity_check_eqns_gallager = int(total_string_length * 0.6) 
#     alice_thread.parity_binary_matrix = gallager_matrix(number_of_parity_check_eqns_gallager, total_string_length, column_weight, row_weight)
    alice_thread.parity_binary_matrix = randomMatrix(total_string_length, number_of_parity_check_eqns_gallager, column_weight)
    alice_thread.binary_syndromes = encode(alice_thread.parity_binary_matrix, alice_thread.bases_string, alphabet=2)
コード例 #3
0
ファイル: System.py プロジェクト: drheli/full-qkd-system
def LDPC_decode_chunk(alice_thread,
                      bob_thread,
                      number_of_parity_check_eqns,
                      alice_chunk,
                      bob_chunk,
                      attempt,
                      decoder,
                      iterations,
                      frozenFor,
                      column_weight,
                      row_weight=3):
    attempt = 0
    decoded = False
    decoded_string = array([])

    while not decoded:
        print "==================", attempt, "================================"

        # =============In case you want to use gallager type matrix================================================================================
        #         total_string_length = len(alice_chunk)
        #         number_of_parity_check_eqns_gallager = int(total_string_length*column_weight/row_weight)
        #         alice_thread.parity_matrix = gallager_matrix(number_of_parity_check_eqns_gallager, total_string_length, column_weight, row_weight)
        # ==========================================================================================================================================

        alice_thread.parity_matrix = randomMatrix(len(alice_chunk),
                                                  number_of_parity_check_eqns,
                                                  column_weight)
        alice_thread.syndromes = encode(alice_thread.parity_matrix,
                                        alice_chunk, alice_thread.frame_size)

        #============================SEND PARITY CHECK MATRIX & SYNDROMES =======================================
        bob_thread.syndromes = alice_thread.syndromes
        bob_thread.parity_matrix = alice_thread.parity_matrix
        #========================================================================================================

        if attempt == 0:
            transition_matrix = transitionMatrix_data2_python(
                bob_chunk, alice_chunk, bob_thread.frame_size)
            prior_probability_matrix = sequenceProbMatrix(
                bob_chunk, transition_matrix)

        belief_propagation_system = SW_LDPC(bob_thread.parity_matrix,
                                            bob_thread.syndromes,
                                            prior_probability_matrix,
                                            decoder=decoder,
                                            original=alice_chunk)
        decoded_string = belief_propagation_system.decode(
            iterations=iterations, frozenFor=frozenFor)
        is_not_decoded = sum(
            check(bob_thread.parity_matrix, decoded_string,
                  bob_thread.frame_size, bob_thread.syndromes) == False)
        if is_not_decoded == 0:
            decoded = True
        else:
            decoded = False

        attempt += 1

    return decoded_string
コード例 #4
0
ファイル: System.py プロジェクト: hbofffw/full-qkd-system
def LDPC_encode(alice_thread, column_weight=3, row_weight=5):
    total_string_length = len(alice_thread.non_zero_positions)
    
    number_of_parity_check_eqns_gallager = int(total_string_length * column_weight/row_weight)
    
#     alice_thread.parity_matrix = gallager_matrix(number_of_parity_check_eqns_gallager, total_string_length, column_weight, row_weight)
    # bits   - number of encoding strings
    # checks - number of parity check eqns
    # paritis- column weight
    alice_thread.parity_matrix = randomMatrix(total_string_length, number_of_parity_check_eqns_gallager, column_weight)
    alice_thread.syndromes = encode(alice_thread.parity_matrix, alice_thread.non_zero_positions, alice_thread.frame_size)
    
    print "Syndromes", alice_thread.syndromes, len(alice_thread.syndromes), (total_string_length)
コード例 #5
0
ファイル: System.py プロジェクト: KwiatQIM/full-qkd-system
def LDPC_decode_chunk(alice_thread, bob_thread, number_of_parity_check_eqns, alice_chunk, bob_chunk, attempt, decoder, iterations, frozenFor, column_weight,row_weight = 3):
    attempt = 0
    decoded = False 
    decoded_string = array([])
  
    while not decoded:
        print "==================", attempt, "================================"
        
# =============In case you want to use gallager type matrix================================================================================
#         total_string_length = len(alice_chunk)
#         number_of_parity_check_eqns_gallager = int(total_string_length*column_weight/row_weight)
#         alice_thread.parity_matrix = gallager_matrix(number_of_parity_check_eqns_gallager, total_string_length, column_weight, row_weight)
# ==========================================================================================================================================

        alice_thread.parity_matrix = randomMatrix(len(alice_chunk), number_of_parity_check_eqns, column_weight)
        alice_thread.syndromes = encode(alice_thread.parity_matrix, alice_chunk, alice_thread.frame_size)
        
        #============================SEND PARITY CHECK MATRIX & SYNDROMES =======================================
        bob_thread.syndromes = alice_thread.syndromes
        bob_thread.parity_matrix = alice_thread.parity_matrix
        #========================================================================================================
        
        if attempt == 0:
            transition_matrix = transitionMatrix_data2_python(bob_chunk, alice_chunk , bob_thread.frame_size)
            prior_probability_matrix = sequenceProbMatrix(bob_chunk, transition_matrix)
            
        belief_propagation_system = SW_LDPC(bob_thread.parity_matrix, bob_thread.syndromes, prior_probability_matrix, decoder=decoder, original=alice_chunk)
        decoded_string = belief_propagation_system.decode(iterations=iterations, frozenFor=frozenFor)
        is_not_decoded = sum(check(bob_thread.parity_matrix, decoded_string, bob_thread.frame_size, bob_thread.syndromes) == False)
        if is_not_decoded == 0: 
            decoded = True
        else:
            decoded = False
            
        attempt += 1

    return decoded_string
コード例 #6
0
    y = loadtxt("./DarpaQKD/LDPC_bob_ttags8.txt")
    y1 = zeros(len(y), dtype=uint64)
    frame_size = 16
    n = total_string_length = len(alice)
    column_weight = 4
    row_weight = 8

    number_of_parity_check_eqns_gallager = int(total_string_length *
                                               column_weight / row_weight)

    parity_matrix = gallager_matrix(number_of_parity_check_eqns_gallager,
                                    total_string_length, column_weight,
                                    row_weight)
    #     print parity_matrix
    #     print parity_matrix
    c = syndromes = encode(parity_matrix, alice, frame_size)
    b = encode(parity_matrix, y, frame_size)
    d = c ^ b
    m = len(c)
    a2f = get_a2f()
    f2a = get_f2a()

    QBER = 10
    k = int(row_weight * m)  #Bits per checksum
    #     print k
    #     print sum(sum(parity_matrix))
    LL_reg = empty(k, dtype=int64)

    (f_init, a_init, LL_reg) = LL_init()

    success = 0
コード例 #7
0
    
    
    alice = loadtxt("./DarpaQKD/LDPC_alice_ttags8.txt")
    y = loadtxt("./DarpaQKD/LDPC_bob_ttags8.txt")
    y1 = zeros(len(y), dtype = uint64)
    frame_size = 16
    n = total_string_length = len(alice)
    column_weight = 4
    row_weight = 8
    
    number_of_parity_check_eqns_gallager = int(total_string_length*column_weight/row_weight)
    
    parity_matrix = gallager_matrix(number_of_parity_check_eqns_gallager, total_string_length, column_weight, row_weight)
#     print parity_matrix
#     print parity_matrix
    c = syndromes=encode(parity_matrix,alice,frame_size)
    b = encode(parity_matrix,y,frame_size)
    d = c^b
    m = len(c)
    a2f = get_a2f()
    f2a = get_f2a()
    
    QBER = 10
    k = int(row_weight*m) #Bits per checksum
#     print k
#     print sum(sum(parity_matrix))
    LL_reg = empty(k, dtype = int64)

    (f_init, a_init, LL_reg) = LL_init()
    
    success = 0
コード例 #8
0
    #                      [ 1,  1,  0,  0,  0,  0,  0,  1,  0,  0,  0,  1,],
    #                      [ 0,  0,  0,  1,  0,  1,  0,  0,  1,  1,  0,  0]])
    #     print "Parity matrix\n",parity_matrix
    #     print "column weight of first column",sum(parity_matrix[:,0])
    number_of_parity_check_eqns_gallager = int(total_string_length * 0.52)
    k = 0
    for i in range(10):
        parity_matrix = randomMatrix(total_string_length,
                                     number_of_parity_check_eqns_gallager, 3)
        a = array([])
        for i in range(parity_matrix.shape[0]):
            #         print sum(parity_matrix[i,:])
            a = append(a, sum(parity_matrix[i, :]))
        print min(a), "-", max(a)
        #         print parity_matrix
        syndromes = encode(parity_matrix, alice, alphabet=frame_size)
        #         print "syndromes: ", syndromes
        #  ======================================

        # ============ decode ===================
        decoder = 'bp-fft'
        iterations = 70
        frozenFor = 5

        set_printoptions(threshold=nan)
        transition_matrix = transitionMatrix_data2_python(
            bob, alice, frame_size)
        prior_probability_matrix = sequenceProbMatrix(bob, transition_matrix)
        #
        #     print "prior_probability_matrix\n",prior_probability_matrix
        #     print "Transition matrix\n",transition_matrix