All posts by Cocoa

在非越狱的iOS上安装系统级的自定字体

在很久之前写过一个笔记,iOS上CoreText加载字体并使用,然后今天做的是在非越狱的iOS上安装系统级的自定字体,其实就是模拟Apple Configurator生成配置文件,然后安装字体,方便的地方在于不需要用电脑,也不必下载Apple Configurator,直接在下面的表单里填上对应的项即可。





填写好基本的信息——字体链接、描述、名字——之后,就可以点“INSTALL FONT”了。

那么这个有什么用呢?在支持自定字体的程序中(比如Pages、Numbers、Keynote等等),我们可以使用自己喜欢的字体,不用越狱,也不用打开iFunbox一类的软件折腾。

Continue reading 在非越狱的iOS上安装系统级的自定字体

看,有灰机!——接收应答机ADS-B信号追踪飞机

根据能查到的资料,飞机在飞行过程中,其数据链有ADS-B(广播式自动相关监视,Automatic dependent surveillance – broadcast)ACARS(飞机通信寻址与报告系统,Aircraft Communication Addressing and ReportingSystem)。目前的话,ADS-B是用得比较多的一种。

有了数据链之后,由于数据链只是一种编码方式,我们需要的还有通信方式。通信方式有SSR(二次监视雷达,Secondary Surveillance Radar),VHF(甚高频,Very High Frequency),SATCOM(卫星通信,Satellite Communications)等。ADS-B是工作在SSR平台下的;而ACARS是通过VHF和空管进行双向通信的。如果离开了VHF的覆盖范围,ACARS就会自动切换到SATCOM方式。

工作在SSR平台下的ADS-B的大致流程如下。地面SSR发出询问电脉冲,飞机上的Transponder(二次雷达应答机)收到这个询问脉冲后,向地面SSR发回一组数据,其中包括飞机的飞行高度、速度和飞机SSR代码等信息。飞机上ADS-B发送的频率是1090MHz,只要我们用的芯片能接收这个到频率的信号,我们就可以追踪飞机了。

Continue reading 看,有灰机!——接收应答机ADS-B信号追踪飞机

Google Code Jam 2016 Round 1B Problem A in J language

You just made a new friend at an international puzzle conference, and you asked for a way to keep in touch. You found the following note slipped under your hotel room door the next day:

"Salutations, new friend! I have replaced every digit of my phone number with its spelled-out uppercase English representation ("ZERO", "ONE", "TWO", "THREE", "FOUR", "FIVE", "SIX", "SEVEN", "EIGHT", "NINE" for the digits 0 through 9, in that order), and then reordered all of those letters in some way to produce a string S. It's up to you to use S to figure out how many digits are in my phone number and what those digits are, but I will tell you that my phone number consists of those digits in nondecreasing order. Give me a call... if you can!"

Continue reading Google Code Jam 2016 Round 1B Problem A in J language

Network traffic over DNS

之前试着实现了一下黑暗幽灵(DCM)木马的数据传输方式,A rather marvelous means to send data anonymously via fake DNS query,于是就想着,DCM是通过DNS包附带信息,传给DNS服务器,然后在关键节点上抓包来实现的数据传输。那么这些数据也会到指定的DNS服务器上,假如我们自己实现这样的一个DNS服务器,那不就可以当作代理使用了?

在Google之后,我发现这样的想法已经有人实现了——iodine。不过这里并不想讲如何使用这个软件,下面要讲的就是自己实现一个!

服务端的构想如下,有一个进程监听UDP 53端口,客户端发送身份请求,服务端回应一串字符作为身份代码(后文作identification),然后就算是建立起了链接。这一步类似于cookie或者session的概念。

随后,客户端带着identification,再去请求各种服务。那么这些服务是怎么来的呢?服务端上,有不同的"应用"向监听在UDP 53端口的进程注册服务。这一点类似于node.js里express的想法。

并且,很多需要登录的公共热点都是对DNS包放行的,于是23333

Continue reading Network traffic over DNS

Google Code Jam 2016 Round 1A Problem C in J language

You are a teacher at the brand new Little Coders kindergarten. You have N kids in your class, and each one has a different student ID number from 1 through N. Every kid in your class has a single best friend forever (BFF), and you know who that BFF is for each kid. BFFs are not necessarily reciprocal -- that is, B being A's BFF does not imply that A is B's BFF.

Your lesson plan for tomorrow includes an activity in which the participants must sit in a circle. You want to make the activity as successful as possible by building the largest possible circle of kids such that each kid in the circle is sitting directly next to their BFF, either to the left or to the right. Any kids not in the circle will watch the activity without participating.

What is the greatest number of kids that can be in the circle?

Continue reading Google Code Jam 2016 Round 1A Problem C in J language

Google Code Jam 2016 Round 1A Problem B in J language

When Sergeant Argus's army assembles for drilling, they stand in the shape of an N by square grid, with exactly one soldier in each cell. Each soldier has a certain height.

Argus believes that it is important to keep an eye on all of his soldiers at all times. Since he likes to look at the grid from the upper left, he requires that:

  • Within every row of the grid, the soldiers' heights must be in strictly increasing order, from left to right.
  • Within every column of the grid, the soldiers' heights must be in strictly increasing order, from top to bottom.

Although no two soldiers in the same row or column may have the same height, it is possible for multiple soldiers in the grid to have the same height.

Since soldiers sometimes train separately with their row or their column, Argus has asked you to make a report consisting of 2*N lists of the soldiers' heights: one representing each row (in left-to-right order) and column (in top-to-bottom order). As you surveyed the soldiers, you only had small pieces of paper to write on, so you wrote each list on a separate piece of paper. However, on your way back to your office, you were startled by a loud bugle blast and you dropped all of the pieces of paper, and the wind blew one away before you could recover it! The other pieces of paper are now in no particular order, and you can't even remember which lists represent rows and which represent columns, since you didn't write that down.

You know that Argus will make you do hundreds of push-ups if you give him an incomplete report. Can you figure out what the missing list is?

Continue reading Google Code Jam 2016 Round 1A Problem B in J language

A rather marvelous means to send data anonymously via fake DNS query

前几天freebuf上出现了一篇文章,黑暗幽灵(DCM)木马详细分析,这个木马为了防止被直接找出服务器地址,在上传用户数据时伪装成了DNS查询,然后在关键节点捕获带有特定标识的网络包后进行转发。

抛开一切,不得不说这样的想法还是很好玩。于是就来写了个demo实验了一下。

假定我们伪装成查询www.google.com的IPv4地址,实际发送的数据是nise DNS query

Continue reading A rather marvelous means to send data anonymously via fake DNS query

Google Code Jam 2016 Round 1A Problem A in J language

On the game show The Last Word, the host begins a round by showing the contestant a string S of uppercase English letters. The contestant has a whiteboard which is initially blank. The host will then present the contestant with the letters of S, one by one, in the order in which they appear in S. When the host presents the first letter, the contestant writes it on the whiteboard; this counts as the first word in the game (even though it is only one letter long). After that, each time the host presents a letter, the contestant must write it at the beginning or the end of the word on the whiteboard before the host moves on to the next letter (or to the end of the game, if there are no more letters).


For example, for S = CAB, after writing the word Con the whiteboard, the contestant could make one of the following four sets of choices:

  • put the A before C to form AC, then put the B before AC to form BAC
  • put the A before C to form AC, then put the B after AC to form ACB
  • put the A after C to form CA, then put the B before CA to form BCA
  • put the A after C to form CA, then put the B after CA to form CAB

Continue reading Google Code Jam 2016 Round 1A Problem A in J language

Quinary Search Tree

update (2016-04-05):
    Ternary Search Tree (improved)的实现有误,将稍后更正。

There is always a topic that how to store a set of strings. Throughout the years, many kinds of data structure had been proposed and applied, for instance, hash tables, binary search tree, digital search tree, ternary search tree and so on and so forth.

如何存储一组字符串总是一个经久不衰的话题。在这些年间,有许多种不同的数据结构不断被提出和应用,例如哈希表、二分搜索树、数字查找树、三元搜索树等等。

Let's begin with ternary search tree which is proposed by Jon and Robert at Pricenton[1]. There is one more pointer in the node compared with binary search tree, and it's the exactly minor change that not only makes it combine the time efficiency of digital tries with the space efficiency of binary search trees, but also provides more features like prefix search and fuzz search.

让我们从三元搜索树开始,它是由Jon和Robert在Pricenton[1]提出的。和二分搜索树相比起来,它的每个节点中多了一个指针,也正是这么一个小小的改动,不仅使它结合了数字查找树的时间效率和二分搜索树的空间效率,还使得它提供了诸如前缀搜索和模糊搜索这样的特性。

But can we make it more efficient in time with a tolerable space increment? We need to analyse the algorithm and the data structure of ternary search tree.

但是我们能在可容忍的空间使用增加上,进一步提高它的时间效率吗?我们需要分析三元搜素树的算法与结构。

Continue reading Quinary Search Tree

Enhancement of Ternary Search Tree

As we memtioned in the Application of Ternary Search Tree, a typical node structure of TST is

正如我们在Ternary Search Tree的应用中提到的那样,一个典型的TST结点的结构题如下

typedef struct tsnode {
    char c;
    struct tsnode * le, * eq, * gt;
} tsnode, * tstree;

Its insertion and searching are really fast when the string in given strings set is short (I'm not going to define the exactly length of a string that we could say it's short, but we will see the decrement of running time after we applying the improvement). When the string length increases, the insertion and searching time grow, of course. The question is, we only compare one char at a time.

当给定输入集的字符串都比较短的时候(我并不打算定义低于多少个字节长才叫短,但是在应用了改进之后,我们将会明显看见运行时间的减少)。当字符串长度增加时,理所当然的,插入和搜索的时间也会增加。但问题在于,我们一次只比较了一个字符。

Continue reading Enhancement of Ternary Search Tree