羅德興老師的教學歷程檔案 - 109-2 資訊技術 - 主題A2:量子程式設計入門
 

企業資訊與管理系
助理教授/日導
羅德興


歷程檔案 Portfolio

    主題A2:量子程式設計入門


    一、環境介紹
    REFERENCES:
    請參考:Introduction to Quantum Programming with Google Cirq

    Cirq basics (Cirq 基礎)
    https://quantumai.google/cirq/tutorials/basics

    https://www.mlq.ai/quantum-programming-google-cirq/

    1. 在 Windows 上安裝 Python

    https://www.python.org/downloads/windows/

    2. 在 Windows 上 安裝 Cirq (或直接跳到  二、進入 Cirq)

    Installing on Windows

    To get started we'll pip install cirq
    已增加到 Python 的路徑,在作業系統下 (如C:\>) 鍵入指令
    pip install cirq
    (視電腦效能與網路環境,這可能得花上一些時間)

    3. 環境測試 <檢查 Cirq  是否可以 work?>

    Foxtail 是一個 2*11 的網格 (可能是 Google 早期的量子線路硬體架構)


    (1) 在 Python 的執行環境下
    import cirq
    print(cirq.google.Foxtail)

    或是
    (2) 已增加到 Python 的路徑,在作業系統下 (如C:\>) 鍵入指令
    python -c "import cirq; print(cirq.google.Foxtail)"

    The above (1),(2)  should print the following results:
    以上(1) 或 (2) 應該會印出如下結果:

     


    二、進入 Cirq

    1. Introduction to Google Cirq

    In order to program and simulate quantum circuits, we're going to make use of Google's Cirq framework, which is:

    A python framework for creating, editing, and invoking Noisy Intermediate Scale Quantum (NISQ) circuits.

    To get started we'll pip install cirq and then import cirq.

    To check if everything is installed correctly we can check out a demo quantum circuit with print(cirq.google.Foxtail):

    Now that we've got everything installed let's move on to a real quantum programming task.


    【程式例 test0.py】(download)

    # This is a test program 檢查是否安裝妥當?

    # 在系統下使用 python test0.py  執行


    # 請先行安裝 Cirq: To get started we'll pip install cirq

    import cirq

    # check out a demo quantum circuit with print(cirq.google.Foxtail):

    print(cirq.google.Foxtail)



    2. Quantum Hello World

    We're now going to define our first quantum cirquit on a quantum simulator.

    To do this we'll first visualize the circuit with Quirk, which is a quantum circuit simulator:

    We can see we have two |0 qubits and we can drag gates onto these circuits, which will change the output accordingly.

    Jumping back to our notebook, the first step we want to do for a basic quantum circuit is define the number of qubits, logic gates, and output.

    For our qubits we use the built-in GridQubit and loop through the length two times because we want to create a 3x3 row and a column matrix.

    # define the length length = 3  # define the qubits qubits = [cirq.GridQubit(i, j) for i in range(length) for j in range(length)]  # print the qubits print(qubits)

    Now that we've created the qubits we want to add quantum logic gates to them.

    Hadamard Gate

    The first quantum logic gate we'll look at is the Hadamard gate, or the H-gate.

    The Hadamard gate is very important because it re-distributes the probability of the all the input lines so that the output lines have an equal chance of being a 0 and 1.

    Let's go back to our simulator and drag an H-gate onto one of the |0 circuits:

    Now that we have the H-gate we can see the output has a 50% chance of being measured ON, or 1.

    Let's now add an H-gate to all of the qubits in our circuit where the row + column index, or i + j, is even.

    First we define a Circuit object and we are going to add to this with circuit.append.

    Inside append we pass in the Hadamard gate with cirq.H(q) and loop through the qubits to check if they're even or not.

    # define a circuit circuit = cirq.Circuit() circuit.append(cirq.H(q) for q in qubits if (q.row + q.col) % 2 == 0) print(circuit)

    We can see we have 5 H-gates.

    Pauli's X Gate

    Let's now add a new gate called the Pauli X gate, which is the quantum equivalent of the NOT gate for classical computers.

    A NOT gate flips the input state, so a 0 as input becomes 1 as output, and vice versa.

    We can see the output of our |0 circuit has is now ON, so the chance of measuring a 1 is 100%, and if we add another Pauli X gate our output becomes OFF.

    Let's noww add a Pauli X gate to our cirq circuit.

    circuit.append(cirq.X(q) for q in qubits if (q.row + q.col) % 2 == 1) print(circuit)

    Let's now look at how a quantum circuit is represented in Cirq.

    A Cirq Circuit is made up of group of Moments, and a Moment is made up of a group of operations.

    If we look at our Pauli X gate above one issue is that the H-gates and the X-gates get executed at different times.

    Instead, we want both the H and X gates to be executed at the same time.

    So what we're looking for is to have one Moment with both the H and X-gates.

    To make sure we only have one Moment we're going to set our strategy equal to cirq.InsertStrategy.EARLIEST, which governs the time of the operation execution.

    # redefing the circuit with an InsertStrategy circuit = cirq.Circuit() circuit.append([cirq.H(q) for q in qubits if (q.row + q.col) % 2 == 0],               strategy=cirq.InsertStrategy.EARLIEST) circuit.append([cirq.X(q) for q in qubits if (q.row + q.col) % 2 == 1],               strategy=cirq.InsertStrategy.EARLIEST) print(circuit)
    # look at the circuit moments for i, m in enumerate(circuit):   print('Moment {}: {}'.format(i,m))

    Now we can see we only have one Moment in the Circuit.

    3. Creating Quantum Circuits

    As mentioned, a Circuit is defined as a set of Moments.

    A Moment is defined as a set of operations that can be executed on Qubits.

    So to create new Circuits we need to create new Moments, which we can do with cirq.moments().

    Here's what we're going to do:

    • We're first going to define our grid of qubits
    • We then apply an X-gate at Qubit location (0,0)
    • We then turn it into an operation
    • We then define new Moments
    • We the combine Moments together to create a new circuit
    # creating a grid of qubits qubits = [cirq.GridQubit(x, y) for x in range(3) for y in range(3)] print(qubits)
    # applying a gate at Qubit location (0,0) x_gate = cirq.X  # turn in into an operation x_op = x_gate(qubits[0]) print(x_op)
    # define a Moment cz = cirq.CZ(qubits[0], qubits[1]) x = cirq.X(qubits[2]) moment = cirq.Moment([x, cz]) print(moment)
    # define a Circuit by combining Moments togeteher cz01 = cirq.CZ(qubits[0], qubits[1]) x2 = cirq.X(qubits[2]) cz12 = cirq.CZ(qubits[1], qubits[2]) moment0 = cirq.Moment([cz01, x2]) moment1 = cirq.Moment([cz12]) circuit = cirq.Circuit((moment0, moment1)) print(circuit)

    Insert Strategies

    Let's now look at InsertStrategy class in a bit more detail, you can find the documentation for it here.

    There are a few different types of InsertStategy attributes we can use to create a quantum circuit with Cirq.

    Insert strategies can help the execution of the circuit and can make the creation of new Moments easier.

    As we've discussed whenever we create a quantum circuit there are 3 main tasks:

    1. Define the initial qubit state
    2. Define the operations and Moments
    3. Measure the output

    InsertStrategy is a crucial part of the second step when we add new operations on to Moments.

    Let's look at an example:

    • We're first going to import the CZ and H gates from cirq.ops and ImportStrategy from cirq.circuits
    • We're then going to define 3 qubits with cirq.GribQubit
    from cirq.ops import CZ, H from cirq.circuits import InsertStrategy q0, q1, q2 = [cirq.GridQubit(i, 0) for i in range(3)]

    Next let's look at InsertStrategy.EARLIEST, which adds the operation onto the very first Moment.

    circuit = cirq.Circuit() circuit.append([CZ(q0, q1)]) circuit.append([H(q0), H(q2)], strategy=InsertStrategy.EARLIEST) print(circuit)

    We can see the H-gate is inserted on the first Moment of the circuit.

    Next let's look at InsertStrategy.NEW, which creates a new Moment and adds the operation to it.

    circuit = cirq.Circuit() circuit.append([H(q0), H(q1), H(q2)], strategy=InsertStrategy.NEW) print(circuit)

    Next let's look at InsertStrategy.INLINE, which adds operations in a Moment a specific instant.

    circuit = cirq.Circuit() circuit.append([CZ(q1, q2)]) circuit.append([CZ(q1, q2)]) circuit.append([H(q0), H(q1), H(q2)], strategy=InsertStrategy.INLINE) print(circuit)

    Finally let's look at InsertStrategy.NEW_THEN_INLINE, which as the name suggests is a combination of the NEW and INLINE strategy.

    circuit = cirq.Circuit() circuit.append([H(q0)]) circuit.append([CZ(q1, q2), H(q0)], strategy=InsertStrategy.NEW_THEN_INLINE) print(circuit)

    Now that we've created quantum circuits, let's create a simple quantum simulator with Cirq.

    4. Creating a Quantum Simulator with Cirq

    Let's now use Cirq to simulate quantum phenomenon on a classical computer.

    Cirq has a built-in package for a quantum simulator, which displays the corresponding output based on the circuit provided.

    For this example, we're going to simulate 2 qubits:

    q0 = cirq.GridQubit(0,0) q1 = cirq.GridQubit(0,1) 

    Now that we've declared our qubits we want to declare a basic_circuit, a method for the circuit model:

    # create a basic circuit constructor def basic_circuit(meas=True):   sqrt_x = cirq.X**(0.5)   yield sqrt_x(q0), sqrt_x(q1)   yield cirq.CZ(q0, q1)   yield sqrt_x(q0), sqrt_x(q1)   if meas:     yield cirq.measure(q0, key='alpha'), cirq.measure(q1, key='beta')

    We then define a new circuit and append our basic_circuit method to it:

    circuit = cirq.Circuit() circuit.append(basic_circuit()) print(circuit)

    Now let's run this circuit with the Cirq simulator:

    from cirq import Simulator simulator = Simulator() result = simulator.run(circuit) print(result)   

    5. The Quantum Fourier Transform Operation

    Now let's move on to our first real project and create the quantum Fourier transform circuit and simulate it with Cirq.

    Here's a brief summary of a Fourier transform:

    The term Fourier transform refers to both the frequency domain representation and the mathematical operation that associates the frequency domain representation to a function of time.

    In simpler terms, a Fourier transform converts a single energy distribution into its constituent energy.

    For example, a musical chord can be expressed in terms of the volume and frequencies of the constituent notes.

    Let's now extend this concept to a quantum circuit, here's the definition of a quantum Fourier transform:

    The quantum Fourier transform is the classical discrete Fourier transform applied to the vector of amplitudes of a quantum state, where we usually consider vectors of length N:=2.

    This is similar to the Hadamard gate which redistributes the entire energy distribution, except the quantum Fourier transform is distributed according to the initial energy distribution.

    The quantum Fourier transform can also be seen as a way to convert data, which is encoded with frequency, and convert it into a phase representation.

    phase refers to a part of the whole, so if we have a complete phase we've completed an entire cycle.

    In this example we're going to use 8 qubit states, so we will encounter a phase distribution that is divided into 8 parts.

    To summarize, Fourier transform is a redistribution of energy, so when you have an output you can decode the inputs from it.

    Let's now implement a quantum Fourier transform circuit with Cirq.

    Defining the Hadamard Gate

    • We're first going to define a main() method for our app
    • Inside the main() method we're going to create a basic circuit with 4 qubits qft_circuit
    • We create the 4 qubits with our generate_2x2_grid() method and then define the Circuit
    • Inside the Circuit we pass in the operations that will be used for to create the circuit, which are a series of Hadamard operation H(a) and then the CZ swap operations cz_swap on the qubits
    • We then pass in the InsertStrategy.EARLIEST as the strategy and then return the circuit
    • We're then going to create a simulator, pass in the qft_circuit and print the final result using numpy
    import numpy as np import cirq  def main():     qft_circuit = generate_2x2_grid()     print("Circuit:")     print(qft_circuit)      # creating a simulator     simulator = cirq.Simulator()      # pass in the circuit and print the result     result = simulator.simulate(qft_circuit)     print()     print("Final State:")     print(np.around(result.final_state, 3))  def cz_swap(q0, q1, rot):     yield cirq.CZ(q0, q1)**rot     yield cirq.SWAP(q0, q1)  def generate_2x2_grid():     a,b,c,d = [cirq.GridQubit(0,0), cirq.GridQubit(0,1), cirq.GridQubit(1,1),                 cirq.GridQubit(1,0)]     circuit = cirq.Circuit.from_ops(         cirq.H(a),         cz_swap(a, b, 0.5),         cz_swap(b, c, 0.25),         cz_swap(c, d, 0.125),         cirq.H(a),         cz_swap(a, b, 0.5),         cz_swap(b, c, 0.25),         cirq.H(a),         cz_swap(a, b, 0.5),         cirq.H(a),         strategy=cirq.InsertStrategy.EARLIEST,     )     return circuit   if __name__ == '__main__':     main()

    We've now created a quantum Fourier circuit. We can now build off this algorithm to create a quantum annealer, but we'll save that for another article.

    6. Summary: Quantum Programming with Cirq

    In this article we looked at how to program and simulate quantum circuits with the Google's Cirq framework, which is:

    A python framework for creating, editing, and invoking Noisy Intermediate Scale Quantum (NISQ) circuits.

    We started by learning how to define qubits and then add quantum operations to them. We looked at several quantum gates including the Hadamard gate and Pauli's X gate.

    We then discuss how to create quantum circuits.  In Cirq, a Circuit is defined as a set of Moments, and a Moment is defined as a set of operations that can be executed on qubits.

    We then looked at how to create a quantum simulator with Cirq.

    Finally we tied all of this together by creating a quantum Fourier transform circuit and simulating in with Cirq.

    In the next article we'll build on these concepts and look at programming a quantum annealer with D-Wave.

    Resources


    【程式例 test1.py】(download)

    # This is a test program 先產生三個 Qubits
    # 在系統下使用 python test1.py  執行
     
    import cirq
    # define the length
    length = 3
     
    # define the qubits
    qubits = [cirq.GridQubit(i, j) for i in range(length) for j in range(length)]
     
    # print the qubits
    print(qubits)
     
    # define a circuit
    # Hadamard Gate (閘)
    circuit = cirq.Circuit()
    circuit.append(cirq.H(q) for q in qubits if (q.row + q.col) % 2 == 0)
    print(circuit)
     
     
    # 在 cirq circuit (線路)中 增加一個Pauli's X Gate
    circuit.append(cirq.X(q) for q in qubits if (q.row + q.col) % 2 == 1)
    print(circuit)
     
    # Cirq Circuits < moments < operations 
     
    # redefing the circuit with an InsertStrategy
    # 以 插入策略 重新定義  線路
    circuit = cirq.Circuit()
    circuit.append([cirq.H(q) for q in qubits if (q.row + q.col) % 2 == 0],
                  strategy=cirq.InsertStrategy.EARLIEST)
    circuit.append([cirq.X(q) for q in qubits if (q.row + q.col) % 2 == 1],
                  strategy=cirq.InsertStrategy.EARLIEST)
    print(circuit)
     
    # look at the circuit moments
    # 看看 線路 動量
    for i, m in enumerate(circuit):
      print('Moment {}: {}'.format(i,m))
     
     
    # Creating Quantum Circuits
    # 產生量子線路
     
    # creating a grid of qubits
    qubits = [cirq.GridQubit(x, y) for x in range(3) for y in range(3)]
    print(qubits)
     
    # applying a gate at Qubit location (0,0)
    x_gate = cirq.X
     
    # turn in into an operation
    x_op = x_gate(qubits[0])
    print(x_op)
     
    # define a Moment
    cz = cirq.CZ(qubits[0], qubits[1])
    x = cirq.X(qubits[2])
    moment = cirq.Moment([x, cz])
    print(moment)
     
    # define a Circuit by combining Moments togeteher
    cz01 = cirq.CZ(qubits[0], qubits[1])
    x2 = cirq.X(qubits[2])
    cz12 = cirq.CZ(qubits[1], qubits[2])
    moment0 = cirq.Moment([cz01, x2])
    moment1 = cirq.Moment([cz12])
    circuit = cirq.Circuit((moment0, moment1))
    print(circuit)
     
     
    # Insert Strategies
    # 插入策略
    from cirq.ops import CZ, H
    from cirq.circuits import InsertStrategy
    q0, q1, q2 = [cirq.GridQubit(i, 0) for i in range(3)]
     
    # Next let's look at InsertStrategy.EARLIEST, which adds the operation onto the very first Moment.
     
    # NEW InsertStrategy
    # 新增策略
    print('新增策略')
    circuit = cirq.Circuit()
    circuit.append([CZ(q0, q1)])
    circuit.append([H(q0), H(q2)], strategy=InsertStrategy.EARLIEST)
    print(circuit)
     
     
    # Next let's look at InsertStrategy.INLINE, which adds operations in a Moment a specific instant.
    # 在 Moment 中 新增 operations
    print('在 Moment 中 新增 operations')
    circuit = cirq.Circuit()
    circuit.append([CZ(q1, q2)])
    circuit.append([CZ(q1, q2)])
    circuit.append([H(q0), H(q1), H(q2)], strategy=InsertStrategy.INLINE)
    print(circuit)
     
     
    # Finally let's look at InsertStrategy.NEW_THEN_INLINE,
    # which as the name suggests is a combination of the NEW and INLINE strategy.
    # 最後來看看 結合 NEW and INLINE 策略的 InsertStrategy.NEW_THEN_INLINE,
    print('結合 NEW and INLINE 策略的 InsertStrategy.NEW_THEN_INLINE')
    circuit = cirq.Circuit()
    circuit.append([H(q0)])
    circuit.append([CZ(q1, q2), H(q0)], strategy=InsertStrategy.NEW_THEN_INLINE)
    print(circuit)
     
     
    # 4. Creating a Quantum Simulator with Cirq
    # Let's now use Cirq to simulate quantum phenomenon on a classical computer.
    # 在傳統電腦上 使用 Cirq 模擬 量子現象
     
    # simulate 2 qubits:
     
    print('')
    print('simulate 2 qubits 模擬兩顆 qubits')
    q0 = cirq.GridQubit(0,0)
    q1 = cirq.GridQubit(0,1)
     
     
    # create a basic circuit constructor
    def basic_circuit(meas=True):
      sqrt_x = cirq.X**(0.5)
      yield sqrt_x(q0), sqrt_x(q1)
      yield cirq.CZ(q0, q1)
      yield sqrt_x(q0), sqrt_x(q1)
      if meas:
        yield cirq.measure(q0, key='alpha'), cirq.measure(q1, key='beta')
        
    # We then define a new circuit and append our basic_circuit method to it:
     
    circuit = cirq.Circuit()
    circuit.append(basic_circuit())
    print(circuit)
    # Now let's run this circuit with the Cirq simulator:
     
    print('')
    print('simulation 模擬結果')
    from cirq import Simulator
    for i in range(10):
        simulator = Simulator()
        result = simulator.run(circuit)
        print(result)
     







    三、後量子密碼學(Post-Quantum Cryptography,PQC)
    (1)
    https://iis.sinica.edu.tw/zh/page/report/8106.html

    量子世代下的密碼學:機會與挑戰

    (大型)量子電腦能利用秀爾演算法(Shor’s Algorithm)對現今公鑰加密系統造成災難性的影響,這也是少數目前確認的量子計算的殺手級應用之一。秀爾演算法基本上是個利用量子特性尋找週期的演算法,能有效率的破解RSA與橢圓曲線密碼學(Elliptic Curve Cryptography; ECC)。 儘管量子電腦的出現速度比預期的要慢,但NIST的一份報告曾謹慎的預估量子電腦最早可能將於2030年破解橢圓曲線密碼學。

    鑑於轉換現行密碼架構的困難性,這是當今亟待解決的問題。其嚴重性體現在轉換現行密碼架構所需的成本與時間。前者可以從當年解決Y2K問題的成本推估,後者我們則應注意到業界已經花了二十年但仍未完全轉換到AES。後量子密碼學(Post-quantum Cryptography; PQC)是一個快速發展的領域,它通過開發可抵禦量子攻擊的安全密碼系統(通常是公鑰密碼系統)來應對這一挑戰。

    我們也可以將量子視為一把雙刃劍。 儘管可能無法在可見的未來實用化,但量子也增強了好人的能力,使其達成更強安全性或更多的任務。近年來量子密碼學對於當好人取得量子能力時的可能性有豐富且令人興奮的發展。

    後量子密碼學

    密碼學是量子電腦造成最早也最可見實體影響的學科:美國國家標準局 (NIST)在 2015 年就開始討論新一代的,可抗量子的公鑰密碼系統,在 2016 年他們公開向全世界徵求後量子密碼系統,這個甄選過程在 2017 年截止收件。在這四年間,幾乎所有實作派的密碼學家都參與後量子密碼系統的設計,實作和破密。

    NIST 的標準化過程進行到第二階段,在 82 個投稿的系統中有 69 個「完整而正確」,它們成為第一階段的候選者,並被邀請參加 2018 年四月的第一次候選者大會。而幾乎是 NIST 才剛公布全部的名單,後量子密碼學家就已經在分析和攻破這些系統。大概有 50 個沒被攻破的系統中 NIST 挑出 26 個 (其中17個加解密系統和 9 個數位簽章)晉級第二階段,並邀請它們參加 2019 年八月的第二次候選者大會。第三階段預計將在2020六月開始。晉級這一階段的最後決選者中將預計在 2022 年選出勝利者,並在再 1-3 年後標準化。這個過程和 AES 與 SHA-3 的競賽是類似的。

    量子為壞人帶來的能力其實不僅限於量子計算,還有如處理量子信息,利用量子糾纏,與進行量子疊加的操作等,這些能力在不同的密碼學領域,如在Leakage-resilient Cryptography與Tampering-resilient Cryptography領域,以及在分析使用隨機預言機(Random Oracle)的構造的安全性時,可能為壞人帶來優勢。 從理論的角度,了解這些優勢對安全性的影響,以及如何證明安全性是重要的研究課題。這樣的理論研究也會對實務上決定後量子密碼系統的安全參數產生影響。在此研究方向我們的研究集中在探討具有量子信息壞人,發展對此證明安全性的技術。我們也探討量子隨機預言模型下的安全性。

    量子密碼學

    相對於後量子密碼學探討古典密碼系統如何抵禦量子壞人,量子密碼學廣泛地探討當好人也具備量子能力時能實現的密碼學任務。如量子密鑰分發(Quantum Key Distribution; QKD)可以實現具資訊理論安全性(Information-theoretic Security)的安全通訊(Secure Communication),這在古典密碼學(好人不具備量子能力時)可被證明是不可能實現的。又例如當未來資料也變成量子資料時,我們如何對量子資料進行加密,能否像對古典資料一樣,對加密後的量子資料進行運算,也是量子密碼學探討的重要問題。儘管這樣的研究可能在可見的將來無法實用化,量子密碼學是令人興奮的跨領域的學科,需要結合密碼學、量子物理、複雜度理論(Complexity Theory)與資訊理論(Information Theory)等領域的最近技術來研究。量子密碼學也提供了豐富的情境與研究課題,往往能協助發展新的技術與深入的觀察,反過來推動這些領域的研究。

    (2)

    https://medium.com/ikv-tech/%E6%8A%B5%E7%A6%A6%E9%87%8F%E5%AD%90%E9%9B%BB%E8%85%A6%E7%A0%B4%E5%AF%86-cd0cd2516df2

    抵禦量子電腦破密-後量子密碼的現今發展與實務應用的兩難



    密碼學是深奧的學問,在資安領域中數學門檻較高。但近年行動裝置普及、密碼貨幣興起,加上雲端服務發達,它已經融入每個人的生活,守護全球數十億人的數位資產及隱私。然而,近期熱門議題 — — 「量子電腦將毀滅既有密碼系統」,預言量子電腦問世,將毀滅密碼貨幣、國防及資安,將帶來前所未見的威脅。真有如此誇張,宛如人類浩劫? 本篇文章將簡單探討量子電腦對既有密碼系統的影響,包括程度及範圍,以及「後量子密碼」能抵擋量子電腦攻擊,卻尚未廣泛使用的關鍵因素。

    密碼系統分成兩大類,一類是「對稱式」,另外一類是「非對稱式」。預計15至20年後³,若兩千以上量子位元(qubit)的通用型量子電腦(large-scale universal quantum computer)出現,對這兩類密碼系統的威脅並不一樣。

    對稱式密碼系統

    量子電腦運行的Grover演算法(Grover’s algorithm)會使對稱式密碼系統的安全等級減半。亦即,如果現在使用AES 128位元,未來安全強度就剩下64位元,量子電腦破解它的運算量就降為2的64次方。因此要防禦量子電腦並不困難,把密鑰的長度加倍,即可達到與現在一樣的安全強度。舉例來說,若現在使用AES 128,未來用AES 256就可以達到同樣安全性。總體而論,對稱式密碼系統受量子電腦影響有限。

    非對稱式密碼系統

    現今非對稱式密碼系統則受到毀滅式的影響。非對稱式密碼系統也稱「公鑰密碼系統」,包括RSA加密及簽章演算法、Diffie Hellman密鑰交換及橢圓曲線密碼學(Elliptic Curve Cryptography, ECC),已在全世界廣泛使用,其演算法安全性是架構在「質因數分解」還有「離散對數」的難題。但未來15至20年後,量子電腦運行Shor演算法(Shor’s algorithm)能在短時間解開這兩類數學難題。因此現行的演算法無法繼續使用,需要新的公鑰密碼系統來取代。凡是能夠抵抗量子電腦攻擊的公鑰密碼系統就統稱為「後量子密碼」,簡稱為PQC(Post-quantum cryptography)。後量子密碼為數學演算法,核心是量子電腦無法輕易解開的數學難題,因此硬體方面不需量子電腦,可在傳統電腦上運行。

    三年前Google Chrome瀏覽器使用後量子密碼演算法NewHope建立密鑰,所以當時https在Chrome瀏覽器可能已經使用後量子密碼演算法。德國安全晶片大廠英飛凌(Infineon)也有NewHope的概念驗證。然而,在相同的安全等級,實作的效率成為是否採用後量子密碼的關鍵因素。相較於現有的公鑰密碼系統,後量子密碼的密鑰長度較長,數位簽章結果也較占空間,使用上相對不方便,加上現在精通實作及應用的團隊不多,因此尚未普及。

    各應用領域充斥對量子電腦的遐想,但科技工具是中性存在,使用意圖皆出於人意。當一方使用它來保護世界,另一方就會使用它來毀滅世界。也許未來議題不該聚焦於量子電腦問世與否,應預先設想各種應用可能性,發展技術和法規,確保個人、企業和國家能安全無縫接軌至量子時代。 
     

    p.s. 1

    量子世界中有兩個基本原理:

    ——量子疊加,就是指一個量子系統可以處在不同量子態的疊加態上。著名的薛定諤的貓理論曾經形象地表述為一隻貓可以同時既是活的又是死的 [1-2] 

    ——量子糾纏,類似孫悟空和他的分身,二者無論距離多遠都心有靈犀。當兩個微觀粒子處於糾纏態,不論分離多遠,對其中一個粒子的量子態做任何改變,另一個會立刻感受到,並做相應改變。


    p.s. 2 

    有些量子閘Input一個Qubit即可執行,有些則要Input多個Qubit。
    Hadamard Gate就屬於只要一個Qubit當Input。
    在量子計算中,該邏輯閘可以實現對|0〉或者|1〉進行操作,然後成為疊加態。
    由下圖可看出,H可以將一個basis的量子態(|0>或|1>)變成疊加態,是一個非常實用的Gate。
    讀者可以試試計算一下H與H*相乘是不是等於I,也就證實H是一個Unitary matrix。也可以試著計算執行兩次H之後是不是又變回原本帶入的量子態。

    Image for post
    右側為|0>與|1>經過gate執行的結果 左側為Hadamard Gate的矩陣表示



    全部共 0則留言
    登入帳號密碼代表遵守學術網路規範


    文章分類 Labels


    最新文章 Top10

    中華科技大學數位化學習歷程 - 意見反應