对藏宝图进行加密并保存到云端
任意 Wolfram 语言表达式都可被加密.
使用 Blowfish 方法生成一个来自私密密码的强对称密钥.
In[1]:=
![Click for copyable input](assets.zh/encrypt-and-store-a-treasure-map-on-the-cloud/In_32.png)
skeletonKey = GenerateSymmetricKey["Avast ye!", Method -> "Blowfish"]
Out[1]=
![](assets.zh/encrypt-and-store-a-treasure-map-on-the-cloud/O_27.png)
用生成的密钥对宝藏的位置进行加密,保存在 GeoMarker 中并用 GeoGraphics 可视化.
显示完整的 Wolfram 语言输入
Out[2]=
![](assets.zh/encrypt-and-store-a-treasure-map-on-the-cloud/O_28.png)
In[3]:=
![Click for copyable input](assets.zh/encrypt-and-store-a-treasure-map-on-the-cloud/In_34.png)
hiddenTreasure = Encrypt[skeletonKey, treasureMap]
Out[3]=
![](assets.zh/encrypt-and-store-a-treasure-map-on-the-cloud/O_29.png)
现在,通过使用本地密钥,数据已被安全加密,可以将地图上传到 Wolfram 云端.
In[4]:=
![Click for copyable input](assets.zh/encrypt-and-store-a-treasure-map-on-the-cloud/In_35.png)
stowed = CloudPut[hiddenTreasure]
为掩其踪,用 Clear 丢弃原来的地图和密钥.
In[5]:=
![Click for copyable input](assets.zh/encrypt-and-store-a-treasure-map-on-the-cloud/In_36.png)
Clear[hiddenTreasure]
In[6]:=
![Click for copyable input](assets.zh/encrypt-and-store-a-treasure-map-on-the-cloud/In_37.png)
Clear[skeletonKey]
因为密钥来自于一个密码,可以使用原来的输入创建一个新的密钥.
In[7]:=
![Click for copyable input](assets.zh/encrypt-and-store-a-treasure-map-on-the-cloud/In_38.png)
newKey = GenerateSymmetricKey["Avast ye!", Method -> "Blowfish"]
Out[7]=
![](assets.zh/encrypt-and-store-a-treasure-map-on-the-cloud/O_31.png)
现在使用新的密钥取出部署在云端的地图.
In[8]:=
![Click for copyable input](assets.zh/encrypt-and-store-a-treasure-map-on-the-cloud/In_39.png)
reclaimedMap = Decrypt[newKey, CloudGet[stowed]]
Out[8]=
![](assets.zh/encrypt-and-store-a-treasure-map-on-the-cloud/O_32.png)
提取宝藏的位置.
In[9]:=
![Click for copyable input](assets.zh/encrypt-and-store-a-treasure-map-on-the-cloud/In_40.png)
treasureLocation = reclaimedMap[[3, 2]]
Out[9]=
![](assets.zh/encrypt-and-store-a-treasure-map-on-the-cloud/O_33.png)
查询行车路线.
In[10]:=
![Click for copyable input](assets.zh/encrypt-and-store-a-treasure-map-on-the-cloud/In_41.png)
TravelDirections[{$GeoLocation, treasureLocation}]
![](assets.zh/index.zh/M_2.gif)
Out[10]=
![](assets.zh/encrypt-and-store-a-treasure-map-on-the-cloud/O_34.png)
无路可以到达宝藏,下面用 GeoDistance 计算出距离.
In[11]:=
![Click for copyable input](assets.zh/encrypt-and-store-a-treasure-map-on-the-cloud/In_42.png)
GeoDistance[$GeoLocation, treasureLocation]
Out[11]=
![](assets.zh/encrypt-and-store-a-treasure-map-on-the-cloud/O_35.png)
基于这个距离,查找离宝藏最近的机场.
In[12]:=
![Click for copyable input](assets.zh/encrypt-and-store-a-treasure-map-on-the-cloud/In_43.png)
airport = First[GeoNearest["Airport", treasureLocation]]
Out[12]=
![](assets.zh/encrypt-and-store-a-treasure-map-on-the-cloud/O_36.png)
从该机场到宝藏的距离.
In[13]:=
![Click for copyable input](assets.zh/encrypt-and-store-a-treasure-map-on-the-cloud/In_44.png)
GeoDistance[airport, treasureLocation]
Out[13]=
![](assets.zh/encrypt-and-store-a-treasure-map-on-the-cloud/O_37.png)